我遇到基于TASM的汇编代码的问题。我想将“字符串”指针中的字符串转换为十进制数,然后将其打印为十六进制数字。但是,代码只能正确打印右边的前2个字符。这可能有什么问题?
concd SEGMENT
ASSUME cs: concd
ORG 100h
main:
mov ax, 0
mov bx, offset string
mov cx, 0
mov dx, 0
mov si, 0
jump:
mov cx, [bx + si]
cmp cx, 0h ;checking if we reached the end of the string
jz exit
mov dx, ax
mov cx, 9
mult:
add ax, dx ;loop for multiplying by 10
loop mult
mov cx, [bx + si]
sub cx, 30h
add ax, cx
inc si
jmp jump
exit:
call hex
mov ah, 04Ch
mov al, 0
int 21h
hex PROC
mov dx, ax
mov cl, 12
jump2:
mov ax, dx
shr ax, cl
and ax, 15
cmp ax, 9
jng t
add ax, 7h
t: add ax, 30h
call putc
sub cl, 4
jnc jump2
RET
hex ENDP
putc PROC
mov ah, 0Eh
int 10h
RET
putc ENDP
string DB "1234", 0h
concd ENDS
END main
答案 0 :(得分:0)
我做了一些小改动,现在它起作用了。 我评论了“第1阶段”它实际上所做的变化得到了一个字符abd做了一些事情,并且“第2阶段”改变了纠正转换。
现在是OP的时间来弄清楚出了什么问题。
concd SEGMENT
ASSUME cs: concd
ORG 100h
main:
mov ax, cs ;; added - phase 1
mov ds, ax ;; added - phase 1
mov ax, 0
mov bx, offset string
mov cx, 0
mov dx, 0
mov si, 0
jump:
mov ch, 0 ;; Added - phase 2
mov cl, [bx + si] ;; added - phase 2
;mov cx, [bx + si] ;; removed - phase 2
cmp cx, 0h ;checking if we reached the end of the string
jz exit
mov dx, ax
mov cx, 9
mult: ; ax contains the number
;; removed the next 2 lines - phase 2
;add ax, dx ;loop for multiplying by 10
;loop mult
;; added the next 2 lines - phase 2
mov cl, 10
mul cl ; multiply by 10
mov cx, [bx + si]
sub cx, 30h
add ax, cx
inc si
jmp jump
exit:
call hex
mov ah, 04Ch
mov al, 0
int 21h
hex PROC
mov dx, ax
mov cl, 12
jump2:
mov ax, dx
shr ax, cl
and ax, 15
cmp ax, 9
jng t
add ax, 7h
t: add ax, 30h
call putc
sub cl, 4
jnc jump2
RET
hex ENDP
putc PROC
mov ah, 0Eh
int 10h
RET
putc ENDP
string DB "1234", 0h
concd ENDS
END main