Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to use 8086 assembly language to add any two numbers(16 - bits) in Linux (NO

ID: 3771389 • Letter: H

Question

How to use 8086 assembly language to add any two numbers(16 - bits) in Linux (NOT DOS)?

Our teacher wants us to follow the steps:

1. get num1 from the user (input will be string data, use int 80h)

a) display prompt b) capture result

2. get num2 from the user (input will be string data, use int 80h)

a) display prompt b) capture result

3. convert num1 to a numeric value (this step requires converting string data into numeric value)

4. convert num1 to a numeric value (this step requires converting string data into numeric value)

5. add num1 and num2

6. convert sum to string data (ASCII character codes for the digits)

7. display the result (use int 80h)

a) display message b) display sum as character data

The final output should look like this:

Enter the first number: " "

Enther the second number: " "

The sum of the two numbers is:" "

Please do not write it too complicated because I just began to learn this. Appreciate your help.

Explanation / Answer

.model small
.stack 100h
.data

prompt db 13, 10, 'First number:','$'
prompt db 13,10, 'Second number:', '$'
result db 13, 10, 'Sum','$'

;Variables

num1 db ?
num2 db ?
sum db ?

.code

main proc
mov ax,@data ;get data segment address
mov ds,ax ;initialize ds

;Display Prompt
mov ah,9 ;print string function

mov dx,offset prompt;ds:dx points to string
int 21h

; Numbers from the user
mov ah,1 ;input function

int 21h
mov bl,al ;save the value from input
mov num1,al

mov ah,9

lea dx, prompt ;print prompt

int 21h

mov ah,2 ;input second function

int 21h
mov bh,al ;save the value from second input

mov num2,al

;Addition

mov ax,num1 ;move num1 into ax
add ax,num2 ;add first and second numbers together
mov sum,ax ;move the total sum of numbers in sum

;Print Sum

mov ah,9

lea dx, result ; print result

int 21h

mov ah,2

mov dl,bl

int 21h

mov dl,'+' ;display + sign

int 21h

mov dl,bh

int 21h

mov dl,'=' ;display = sign

int 21h

mov dl,bh

int 21h

mov ah,4ch

int 21h

main endp

end main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote