寄存器的显示内容 [英] Display contents of register

查看:170
本文介绍了寄存器的显示内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要帮助显示register.my code的内容below.i已经能够显示数据寄存器值,但我想显示标志的状态。例如:1或0,这将是有益的,如果显示其它寄存器一样也ESI的内容,EBP。

我的code未打印..what我失去了标志的状态

  .text段
全球_start;必须声明为使用gcc
_start:;告诉连接器的入口点MOV EAX,味精;移动信息乳癖到EAX寄存器
MOV [注册],EAX;从EAX为reg变量移动消息
MOV EDX,8;消息长度
MOV ECX,[注册]消息写
MOV EBX,1;文件描述符(标准输出)
MOV EAX,4;系统调用号(SYS_WRITE)
0x80的诠释;调用内核MOV EAX,100
MOV EBX,100
CMP EBX,EAXPUSHF
流行DWORD EAXMOV [save_flags],EAXMOV EDX,8;消息长度
MOV ECX,[save_flags];信息写
MOV EBX,1;文件描述符(标准输出)
MOV EAX,4;系统调用号(SYS_WRITE)
INT 0x80的
MOV EAX,1;系统调用号(sys_exit)
0x80的诠释;调用内核段.data味精DB乳癖,10.bss段章RESB 100save_flags resw 100


解决方案

我不会对任何幻想在这里,因为这似乎是一个家庭作业(两个人都问同样的问题今天)。此code应作为一个函数,它可以具有其性能增强。因为我没有得到的荣誉学位或在课堂上它没有任何意义,我提供最好的解决方案是A,但一个你可以从工作:

  BITS_TO_DISPLAY EQU 32;至少显著的位数以显示(1-32).text段
全球_start;必须声明为使用gcc
_start:;告诉链接入口点    MOV EDX,msg_len;消息长度
    MOV ECX,味精;消息编写
    MOV EBX,1;文件描述符(标准输出)
    MOV EAX,4;系统调用号(SYS_WRITE)
    诠释0x80的;调用内核    MOV EAX,100
    MOV EBX,100
    CMP EBX,EAX    PUSHF
    流行DWORD EAX    ;通过移动最右边的有点过EAX成二进制转换为字符串
    ;进位标志(CF)和转换位为0或1,地点
    ;在save_flags缓冲以相反的顺序。讷终止字符串
    ;在事件中,你曾经想用printf打印出来    MOV ECX,BITS_TO_DISPLAY; EAX的位数寄存器显示
    MOV字节[save_flags + ECX] 0;讷终止二进制字符串的情况下,我们用printf
bin2ascii:
    XOR BL,BL; BL = 0
    SHR EAX,1;右移最高位到进位标志
    ADC BL,'0'; BL = BL + 0 +进位标志
    MOV [save_flags-1 + ECX],BL;地方'0'/'1'到以相反的顺序字符串缓冲区
    十二月ECX
    JNZ bin2ascii;循环直到所有位处理    MOV EDX,BITS_TO_DISPLAY;消息长度
    MOV ECX,save_flags;二进制字符串的地址写
    MOV EBX,1;文件描述符(标准输出)
    MOV EAX,4;系统调用号(SYS_WRITE)
    INT 0x80的    MOV EAX,1;系统调用号(sys_exit)
    0x80的诠释;调用内核段.data
味精DB乳癖,10
msg_len EQU $ - 味精.bss段
save_flags RESB BITS_TO_DISPLAY + 1;添加NUL终止一个字节的情况下,我们用printf

这背后code的想法是,我们不停地变换位(使用 SHR指令)在 EAX 的注册一次正确的位。这被移出寄存器的位被放置在进位标志(CF)。我们可以使用 ADC 加进位标志(0/1),以ASCII码值'0'来获得的'0`和'1'的ASCII值。我们把这些字节到以相反的顺序目标缓冲区,因为我们是从向右移动通过位离开了。

BITS_TO_DISPLAY 可在1到32之间进行设置(因为这是32位code)。如果你如果你想显示32位寄存器的所有位有兴趣在一个寄存器的设置为8的低8位,指定32。

hi i need help displaying contents of a register.my code is below.i have been able to display values of the data register but i want to display flag states. eg 1 or 0. and it would be helpful if to display also the contents of other registers like esi,ebp.

my code is not printing the states of the flags ..what am i missing

section .text
global _start       ;must be declared for using gcc
_start :                     ;tell linker entry point

mov eax,msg         ; moves message "rubi" to eax register
mov [reg],eax       ; moves message from eax to reg variable


mov edx, 8   ;message length
mov ecx, [reg];message to write
mov ebx, 1      ;file descriptor (stdout)
mov eax, 4      ;system call number (sys_write)
int 0x80        ;call kernel

mov eax, 100
mov ebx, 100
cmp ebx,eax

pushf
pop dword eax

mov [save_flags],eax

mov edx, 8        ;message length
mov ecx,[save_flags]         ;message to write
mov ebx, 1          ;file descriptor (stdout)
mov eax, 4          ;system call number (sys_write)
int 0x80     


mov eax, 1      ;system call number (sys_exit)
int 0x80        ;call kernel

section .data

msg db "rubi",10

section .bss

reg resb 100

save_flags resw 100

解决方案

I'm not going for anything fancy here since this appears to be a homework assignment (two people have asked the same question today). This code should be made as a function, and it can have its performance enhanced. Since I don't get an honorary degree or an A in the class it doesn't make sense to me to offer the best solution, but one you can work from:

    BITS_TO_DISPLAY equ 32       ; Number of least significant bits to display (1-32)

section .text
global _start                    ; must be declared for using gcc
_start :                         ;    tell linker entry point

    mov edx, msg_len             ; message length
    mov ecx, msg                 ; message to write
    mov ebx, 1                   ; file descriptor (stdout)
    mov eax, 4                   ; system call number (sys_write)
    int 0x80                     ; call kernel

    mov eax, 100
    mov ebx, 100
    cmp ebx,eax

    pushf
    pop dword eax

    ; Convert binary to string by shifting the right most bit off EAX into
    ; the carry flag (CF) and convert the bit into a '0' or '1' and place
    ; in the save_flags buffer in reverse order. Nul terminate the string
    ; in the event you ever wish to use printf to print it

    mov ecx, BITS_TO_DISPLAY     ; Number of bits of EAX register to display
    mov byte [save_flags+ecx], 0 ; Nul terminate binary string in case we use printf
bin2ascii:
    xor bl, bl                   ; BL = 0
    shr eax, 1                   ; Shift right most bit into carry flag
    adc bl, '0'                  ; bl = bl + '0' + Carry Flag
    mov [save_flags-1+ecx], bl   ; Place '0'/'1' into string buffer in reverse order
    dec ecx
    jnz bin2ascii                ; Loop until all bits processed

    mov edx, BITS_TO_DISPLAY     ; message length
    mov ecx, save_flags          ; address of binary string to write
    mov ebx, 1                   ; file descriptor (stdout)
    mov eax, 4                   ; system call number (sys_write)
    int 0x80

    mov eax, 1                   ;system call number (sys_exit)
    int 0x80                     ;call kernel

section .data
msg db "rubi",10
msg_len equ $ - msg

section .bss
save_flags resb BITS_TO_DISPLAY+1 ; Add one byte for nul terminator in case we use printf

The idea behind this code is that we continually shift the bits (using the SHR instruction) in the EAX register to the right one bit at a time. The bit that gets shifted out of the register gets placed in the carry flag (CF). We can use ADC to add the value of the carry flag (0/1) to ASCII '0' to get an ASCII value of '0` and '1'. We place these bytes into destination buffer in reverse order since we are moving from right to left through the bits.

BITS_TO_DISPLAY can be set between 1 and 32 (since this is 32-bit code). If you are interested in the bottom 8 bits of a register set it to 8. If you want to display all the bits of a 32-bit register, specify 32.

这篇关于寄存器的显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆