Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

assembly - Adding Two Numbers from Input

I'm trying to write this little program which accepts 2 integers and adds them and displays them to the user. I manage to write the entire program and save the variables (number1, number2), and now I have to store number1 + number2 in result.

Here's the code. Where does the add function go?

segment .data 

    msg db "Please enter a digit ", 0xA,0xD 
    len equ $ - msg 

segment .bss

    number1 resb 10 
    number2 resb 10 
    result resb 10    

segment .text 

    msg2 db "Please enter a second digit", 0xA,0xD 
    len2 equ $ - msg2 

    msg3 db "The sum is : ", 0xA,0xD 
    len3 equ $ - msg3

global _start 

 _start: 

    mov eax, 4         
    mov ebx, 1         
    mov ecx, msg         
    mov edx, len 
    int 0x80                

    mov eax, 3 
    mov ebx, 0  
    mov ecx, number1 
    mov edx, 10 
    int 0x80            

    mov eax, 4        
    mov ebx, 1         
    mov ecx, msg2          
    mov edx, len2         
    int 0x80

    mov eax, 3  
    mov ebx, 0  
    mov ecx, number2 
    mov edx, 10 
    int 0x80        

    mov eax, 4         
    mov ebx, 1         
    mov ecx, msg3          
    mov edx, len3         
    int 0x80

    ;add result, number1
    ;add result, number2 

    mov eax, 4        
    mov ebx, 1 

    mov ecx, $result         
    mov edx, len3         
    int 0x80


exit:    
    mov eax, 1   
    xor ebx, ebx 
    int 0x80  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...