[英]TASM string to hexadecimal number
我對基於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
我做了一些小改動,現在可以了。 我在“階段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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.