我的第一个汇编程序需要帮助。
我必须将用户输入的值从十进制转换为二进制。
我不知道如何将值显示为小数,以及下一步应该做什么。
谁能一步一步指导我下一步做什么。
.model small
.stack 100h`
.data
txt1 db "Enter binary value:" ,10,13, "$"
txt2 db "BIN: " ,10,13, "$"
.code
main proc
mov ax, @data
mov ds, ax
;clear screen
mov ah,0fh
int 10h
mov ah,0
int 10h
;show first text
mov ah, 9
mov dx, offset txt1
int 21h
call Number
main endp
Number proc
mov cx,5
xor bx,bx
read:
mov ah,0
int 16h
cmp al,'0'
jb read
cmp al, '9'
ja read
mov ah,0eh
int 10h
loop read
Number endp
mov ax, 4c00h
int 21h
end main
我想这对你来说没问题。
; Read an integer from the screen and display the int in binary format
; and continue until number is negative.
again: ; For loop
call read_int ; take the integer from screen
cmp eax,0 ; look if number is not negative
JL end: ; if less than zero program ends.
mov ecx,32 ; for loop we set ecx to 32 ; ATTENTION we not specified type. So compiler will get error.
mov ebx,eax ; we will lost our number in eax, so I take it to ebx
START:
xor eax,eax ; eax = 0
SHL ebx,1 ; shift the top bit out of EBX into CF
ADC eax,0 ; EAX = EAX + CF + 0 ADD CARRY FLAG, so eax is zero we add zero. The new eax will exact value of Carry Flag which is out bit.
call print_int ; Then we print the CF which we took the eax.
LOOP start: ; Loop looks ecx if not 0 it goes start.
call print_nl ; For next number we print a new line
JMP again: ; For take new number
END: ; End of the program.
setc al
也可以代替adc eax,0
,并且在某些 CPU 上效率更高。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)