In this tutorial we will learn:
- How to take input?
- How to print results as output in different formats?
- Making a small application of Arithmetic operations.
Taking inputs:
Every application must take some inputs otherwise its useless. Taking Inputs form users in Assembly language is quite easy. Simply call the read— procedure from the Kip Irvine’s library.
For reading integer inputs:
call readint
This will read an integer as input and store it in eax register temporarily. You can later manipulate this value i.e move it in some other register using the mov instruction or store it in memory variable.
Showing outputs:
For output, type writeint writedec or any other write— procedure from the Kip Irvine’s library.
Small arithmetic operation application:
For making a small application that performs 4 basic arithmetic operations, we used this code:
INCLUDE Irvine32.inc .data var1 DWORD ? var2 DWORD ? .code main PROC call readint mov var1, eax call readint mov var2, eax mov eax, 0 ; Addition mov eax, var1 add eax, var2 call writeint call crlf ; Subtraction mov eax, var1 sub eax, var2 call writeint call crlf ; Multiplication mov eax, var1 imul eax, var2 call writeint call crlf ; Division mov edx, 0 mov eax, var1 mov ebx, var2 div ebx call crlf ; Print quotient call writeint call crlf ; Print remainder mov eax, edx call writedec exit main ENDP END main
Watch this video for explanation of above code and everything: