2016-03-08 204 views
-2

我想用Irvine32库的汇编语言输入用户的两个数字,但不知道如何。这是我迄今为止:用汇编语言输入数字

INCLUDE Irvine32.inc 
.data 

number1 WORD 
number2 WORD 

.code 
main PROC 



exit 
main ENDP 
END main 
+1

Irvine32.inc包含所有可用函数的列表以及解释函数用途的简短注释。 – Michael

回答

1

我不熟悉irvine,但如何编写自己的输入和解码程序?

DOS中间体21/A读取从标准输入线,并把公司到您的缓冲区

从ASCII解码注册是一个更棘手的;你必须走thoug每个数字,并添加它们逐一移位了短路电流值

这里是一个办法,只是有一个想法: (对不起,语法,最多不兼容于MASM,我还是用埃里克·艾萨克森的A86汇编程序)

.org 0100 
JMP start 

buffer: db 10,"   " ; space for 10 digits 

; read input to buffer 
input: mov ah, 0ah   ; input value 
     mov dx, buffer 
     int 21h 
     ret 

; decode buffer to CX 
decode: mov dx,0 
     mov si, buffer+2 
     mov cl, [buffer+1] ; while (numChars>0) 

decLoop: cmp cl,0 
     je decEnd 

     mov ax, dx   ; mul DX by 10 
     shl ax, 2 
     add ax, dx 
     shl ax, 1 
     mov dx, ax 

     mov al,[si]  ; get current digit 
     inc si    ; and point to next one 
     sub al,'0' 
     mov ah, 0 
     add dx, ax   ; add the digit read 

     dec cl    ; numChars-- 
     jmp decLoop 
decEnd: ret 


; main() 
start: call input 
     call decode 
     push dx 
     call input 
     call decode 
     pop cx 

     ; CX now holds first, DX second number 
     ; feel free to do with em what you feel like 

     int 20h    ; quit