我在汇编(FASM)中做了一个sum和sub,试图得到十进制的结果。我写了I' ll以小数为单位的值。当我运行它时,它确实给了我一个输出,但它是一个二进制输出。我可以自己翻译成十进制,但我真正想要的是输出已经是小数。
name "add-sub"
org 100h
mov al, 10 ; bin: 00001010b
mov bl, 5 ; bin: 00000101b
add bl, al
sub bl, 1
mov cx, 8
print: mov ah, 2
mov dl, '0'
test bl, 10000000b
jz zero
mov dl, '1'
zero: int 21h
shl bl, 1
loop print
mov dl, 'b'
int 21h
mov ah, 0
int 16h
ret
答案 0 :(得分:0)
虽然您编写了十进制值,但汇编程序(FASM)将它们转换为"计算机"格式即二进制。要获得十进制输出,您必须将结果转换为"输出"格式即ASCII。该方法在书籍和网上广泛描述。这里有一个满足您需求的示例(FASM,MSDOS,.com):
format binary as "com"
use16
org 100h
mov al, 10 ; bin: 00001010b
mov bl, 5 ; bin: 00000101b
add bl, al
sub bl, 1
movzx ax, bl
call AX_to_DEC
mov dx, DECIMAL
mov ah, 9
int 21h
;mov ah, 0
;int 16h
ret
DECIMAL DB "00000$" ; place to hold the decimal number
AX_to_DEC:
mov bx, 10 ; divisor
xor cx, cx ; CX=0 (number of digits)
First_Loop:
xor dx, dx ; Attention: DIV applies also DX!
div bx ; DX:AX / BX = AX remainder: DX
push dx ; LIFO
inc cl ; increment number of digits
test ax, ax ; AX = 0?
jnz First_Loop ; no: once more
mov di, DECIMAL ; target string DECIMAL
Second_Loop:
pop ax ; get back pushed digit
or al, 00110000b ; AL to ASCII
mov [di], al ; save AL
inc di ; DI points to next character in string DECIMAL
loop Second_Loop ; until there are no digits left
mov byte [di], '$' ; End-of-string delimiter for INT 21 / FN 09h
ret