Assembly 无法将ascii数字添加到数字8086程序集中
我好像撞到墙了,找不到任何关于这个的例子。我需要将ascii字符转换为数字,即用户类型Assembly 无法将ascii数字添加到数字8086程序集中,assembly,x86-16,tasm,Assembly,X86 16,Tasm,我好像撞到墙了,找不到任何关于这个的例子。我需要将ascii字符转换为数字,即用户类型150+123,因此我必须读取ascii中的第一个数字,然后通过从每个数字中减去0将其转换为dec,但问题是。我不知道如何用这些数字创建一个数字,因为用户可以输入1位或5位。请忽略代码中的外来注释。多谢各位 .model small .stack 100h .data prompt1 db "Please enter an action: ", 10, 13, "$" prompt2 db "An
150+123
,因此我必须读取ascii中的第一个数字,然后通过从每个数字中减去0将其转换为dec,但问题是。我不知道如何用这些数字创建一个数字,因为用户可以输入1位或5位。请忽略代码中的外来注释。多谢各位
.model small
.stack 100h
.data
prompt1 db "Please enter an action: ", 10, 13, "$"
prompt2 db "Answer: ", 10, 13, "$"
newline db 10, 13, '$'
buffer db 255 ; Denotes the number of maximal symbols hope
sizeread db 0 ; It will be available on how many characters scanned
buffer_data db 255 dup (?) ; It will be hosted on-line scanned data to fill 255 characters $
.code
start:
mov dx, @data ;
mov ds, dx ;
print_prompt:
mov ah, 9
mov dx, offset prompt1 ; Messages placed in the DX register address
int 21h ; welcome petraukimą
ret
input:
mov ah, 0Ah
mov dx, offset buffer
int 21h
ret
number:
xor bx,bx
xor ax,ax
mov al, 10 ;set al to 0 so i can MUL
mov cx, 5
loopstart: ;start the cycle
cmp [buffer_data+bx], ' ' ;check if I reached a space
je space ; jump to space (the space func will read the + or - sign later on)
mov bx, [bx+1] ; bx++
;Now i got no idea how to go about this....
space:
end start
需要将累加器乘以10(假设输入为十进制,即十六进制乘以16):
xor-ax,ax;将蓄能器归零
mov-cx,10;cx=10
输入:
movzx bx,
cmp bl,'\n';输入结束
我出去了
分界区,‘0’;将ascii字符转换为数值
mul-cx;ax=ax*10,准备下一个数字(假设结果符合16位)
添加ax、bx;ax=ax+bx,添加当前数字
jmp输入
输出:
到达“out”时,cx具有输入数字的数值 请参阅。确实不需要使用
CX
,您可以一直使用AX
。此外,没有mul 10
指令,您应该使用movzx
而不是xor+mov
对。琐碎的评论是没有用的,你应该表现出更高的意义的行。我们知道xor cx,cxzeroescx
,但我们不知道为什么要将其归零,以及使用的是什么。我已经有一段时间没有使用8086汇编了。。。编辑。
xor ax, ax ; zero the accumulator
mov cx, 10 ; cx = 10
input:
movzx bx, <next input char from left to right>
cmp bl, '\n' ; end of input
je out
sub bl, '0' ; convert ascii char to numeric value
mul cx ; ax = ax*10, prepare for next digit (assuming result fits in 16 bits)
add ax, bx ; ax = ax + bx, add current digit
jmp input
out: