【发布时间】:2012-04-02 21:38:29
【问题描述】:
我正在尝试将使用此代码读取的字符串转换为二进制和十六进制。
READ_STRING:
MOV DX, offset buffer
MOV AH, 0Ah
INT 21h
MOV SI, 1d
MOV AX, 0
XOR CX, CX
MOV CL, buffer[SI]
INC SI
LOOP_1:
MOV DX, 10
MUL DX
MOV DL, buffer[SI]
SUB DL, 30h
MOV DH, 0
ADD AX, DX
INC SI
LOOP LOOP_1
RET
到目前为止,我有这个二进制输出代码,但它总是打印“1001”(十进制的 9):
NEXT:
XOR AX, AX
XOR BX, BX
XOR CX, CX
MOV CL, 2
MOV AL, byte ptr[nombre]
MOV DI, offset binaire
; DIV : divide AX by CL. Remainder in AH and result in AL
LOOP:
DIV CL ; remainder in AH, quotient in AL
ADD AH, '0' ; 0 -> '0' , 1 -> '1'
MOV [DI], AH ; Saves the remainder in the array
INC DI
MOV AH, 0 ; reset AH for next division
CMP AL, 0 ; if result is 0, end
JNE LOOP
;Prints the binary number
MOV DX, offset binaire
CALL WRITE_STRING
谢谢!如果您还需要什么,尽管问。
【问题讨论】:
-
不要尝试直接在汇编程序中编写复杂的算法。先用高级语言开发算法,再翻译。
-
... 或让编译器为您翻译。
-
如果你要学习汇编程序,不要学习 8086、80x86、MIPS、ARM - 任何东西,除了 16 位 DOS 808x ;)。很好的参考,如果你有兴趣:savannah.nongnu.org/projects/pgubook
-
@Carl 我该怎么做?它会与 MASM 兼容吗?
-
我猜想获得一个 16 位 DOS 编译器 - 通常您需要稍微调整反汇编器的输出以使其与您的汇编器一起工作,但这通常并不可怕。
标签: assembly binary masm x86-16