how to convert binary to decimal in asm x86?

ぐ巨炮叔叔 提交于 2019-12-11 17:46:12

问题


I have no idea what is wrong with my coding in DISPLAY_IN_DECIMAL. They kept giving me this error.

 Assembling: coa.asm
coa.asm(314) : error A2006:undefined symbol : decimalArray
 DISPLAY_IN_DECIMAL(3): Macro Called From
  coa.asm(314): Main Line Code
Press any key to continue . . .

I thought it might be something wrong with my decimalArray but I'm not sure what.

This is the code part where I finish all of my binary display. Nothing seems wrong.

counter db 0
        X db 00000000B
        Y db 00000000B

        deciamlArray byte 8 DUP (' ')

        decimalResult db ?
        dec1 db ?

        .code
       DISPLAY_IN_BINARY MACRO result
            local L5, printBinary, print0, print1, nextBit

            PUSH ax
            MOV al, result
            MOV cx, 8

            printBinary:
            TEST al, 10000000b    ;1 in 10000000b indicate that the bit to be compare and print out
            JZ    print0
            JNZ print1

            print1:
            displayResult1  ;If bit of result not equal to 0 ,print 1
            SHL al, 1
            JMP nextBit

            print0:     ;If bit of result = 0,print 0
            displayResult0
            SHL al, 1
            JMP nextBit

            nextBit:
            LOOP printBinary

            POP ax
        ENDM  

But when I try to work on my decimal they gave me the error stated right above just now. I thought it might be something wrong with my decimalArray but I'm not sure.

DISPLAY_IN_DECIMAL MACRO result
    local L1,L2,L3
    MOV SI, OFFSET result
    MOV DI, OFFSET decimalArray
    MOV decimalResult, 0
    MOV CX, 8

    L1:
        MOV AL, [SI]    
        CMP AL, '1'
        JE L2
        JMP L3
    L2 :
        MOV AL, 0
        MOV AL, [DI]
        ADD decimalResult, AL
        JMP L3
    L3:
        INC SI
        INC DI
        LOOP L1
    MOVZX AX, decimalResult
    MOV BL, 10
    DIV BL
    MOV BX, AX
    MOV DH, BH
    MOV dec1, BL
    MOVZX AX, dec1
    MOV BL, 10
    DIV BL
    MOV BX, AX

    MOV AH, 02H     ; print results
    MOV DL, BL
    ADD DL, 30H
    INT 21H
    MOV DL, BH
    ADD DL, 30H
    INT 21H
    MOV DL, DH
    ADD DL, 30H
    INT 21H
 ENDM

回答1:


There's a typo in your code:

deciamlArray byte 8 DUP (' ')

should be:

decimalArray byte 8 DUP (' ')


来源:https://stackoverflow.com/questions/20311344/how-to-convert-binary-to-decimal-in-asm-x86

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!