这里我有一个将单词值转换为字符串的汇编代码
; si -> Offset Address of String
; ax -> Number to be converted
itoa:
push ax ; Backup AX To Stack
push bx ; Backup BX To Stack
push dx ; Backup DX To Stack
push si ; Backup SI To Stack
mov bx,10 ; Set BX to 10 for Dividing the AX by 10
.loop:
div bx ; Divide AX With BX For Getting The Digit And Removing First Digit Of Number
add dl,48 ; Add 48 to DL to Convert Digit to Ascii
mov [cs:si],dl ; Write digit to string
xor dl,dl ; Set DX to 0
inc si ; Increase SI
cmp ax,0 ; Compare AX with 0
jne .loop ; If ax not equals 0 then jump back to start of loop
pop si ; Get Backup Value of SI From Stack
pop dx ; Get Backup Value of DX From Stack
pop bx ; Get Backup Value of BX From Stack
pop ax ; Get Backup Value of AX From Stack
ret ; Return from Subroutine
当我运行此代码时,它输出 AX 中给出的数字的反转,这对我来说是个问题。 我该如何解决这个问题?
最佳答案
我是这样做的
utoa:
mov cx,10
nextdiv:
xor dx,dx
div cx
push dx
or ax,ax
jz nextdigit
call nextdiv
nextdigit:
pop ax
add al,30h
mov [si],al
inc si
ret
它在堆栈上递归,因此最多使用 10 个字,每个数字加上返回值。 我称其为 utoa,因为它是未签名的,如果您想要签名版本 (itoa),请询问。
关于assembly - 如何在 8086 汇编中将 Word 转换为 Ascii 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65553846/