Monday , July 4 2022
Home / Assembly / Assembly #05 – Input/Ouput and Arithmetic operations

Assembly #05 – Input/Ouput and Arithmetic operations

In this tutorial we will learn:

  1. How to take input?
  2. How to print results as output in different formats?
  3. 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:



var1 DWORD ?
var2 DWORD ?

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

main ENDP
END main

Watch this video for explanation of above code and everything:

User Review
0 (0 votes)

About Waleed Baig

I am doing BS Computer Science. I have a passion to learn new technology and spread it. I am more enthusiastic about learning complex algorithm and making creative and efficient solution to a problem.

Check Also

general purpose register

Assembly #2 – What are Registers?

In this tutorial we will learn What are registers? Size of registers and their subdivisions

Leave a Reply

Your email address will not be published.