【发布时间】:2013-06-16 19:12:13
【问题描述】:
我是 8086 汇编的新手,请原谅我草率的代码和可能不必要的行,我是自学成才的。这段代码是我正在制作的另一个程序的片段,它需要用户输入数字。这些特定的行接受输入,然后生成计算机实际可以使用的数字。例如,取 5、4 和 3 并将这些数字“编译”成 543。
问题出现在第 59 行,我尝试将一个数字从内存加载回寄存器 bx,在这种情况下,不是加载正确的数字,如 40(来自 543 ex。)它只是加载一个 1 .
第 59 行之后的一些代码甚至可能无法运行,因为我被卡在那里了。
我可能没有使用正确的寄存器,但同样,我是自学成才,很难在网上找到易于理解的语法信息。
org 100h
mov si, 100d
input1:
mov ah, 1h ;input char
int 21h
push ax
sub al, 30h ;convert ascii to integer
mov dl, al ;put char into dl to be read
mov [si], al ;save char to ram for later
mov ah, 2h ;output char
inc si ;to save on next location in mem
pop ax
cmp al, 13 ;check if done
jne input1
dec si ;insert terination char
dec si ;decrement to save value of si for multilying by ten
push si ;save current si value
inc si ;then continue
mov al, 24h
mov [si], al
pop si
mov cx, 1
compileNum1:
mov ax, 0
mov bx, 0
mov dx, 0
.fixNum:
mov al, [si] ; load last num into ax to be multiplied by 10
mul cx
mov bp, ax
mov [si], bp
dec si
mov al, 10
mov bx, cx
mul bl
mov cx, ax
cmp si, 99d
jne .fixNum
mov si, 100d ;starts number addition
mov ax, [si] ;loads first number
inc si ;prepares second
mov bx, [si] ;loads second
cmp bx, 24h ;checks if there was only 1 number
je .terminate1 ;if there was, goto terminate
add ax, bx ;else add them together
.stloop1:
inc si ;prepares for third, fourth etc
mov bx, [si] ;loads it
cmp bx, 24h ;checks if numbver is 3 digts ot more long (depends on loop)
je .terminate1 ;terminate if so
add ax, bx ;add them together, store in ax
.terminate1:
mov [100d], ax
mov ax, 0 ;clear screen
int 10h
mov ah, 2h ;print char
int 21h
mov ah, 0
int 16h
ret
感谢您的帮助!
【问题讨论】:
标签: assembly binary hex x86-16