0% found this document useful (0 votes)
596 views6 pages

Assembly Language Practical Using Emu8086

The document provides instructions and tasks for a computer architecture lab on inputting and outputting single and multi-digit numbers in Assembly language. It covers signed and unsigned numbers, two's complement notation, and programs to add single and multi-digit numbers. Five tasks are outlined: completing code snippets, running sample programs, writing a program to calculate an equation, reading and summing five integers, and swapping two input values without an extra variable.

Uploaded by

Ayaan Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
596 views6 pages

Assembly Language Practical Using Emu8086

The document provides instructions and tasks for a computer architecture lab on inputting and outputting single and multi-digit numbers in Assembly language. It covers signed and unsigned numbers, two's complement notation, and programs to add single and multi-digit numbers. Five tasks are outlined: completing code snippets, running sample programs, writing a program to calculate an equation, reading and summing five integers, and swapping two input values without an extra variable.

Uploaded by

Ayaan Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB 04

Summary
Items Description
Course Title Computer Architecture
Lab Title Input /output single and multi-digit numbers in Assembly
Duration 3 Hours
Operating System Emu8086
/Tool/Language
Objective Practice how to Input, Output single and multi-digit number.

Input/ Output Single and Multi-digit Number


Objective
• To learn about signed and unsigned numbers
• Practice how to Input, Output single and multi-digit number.
• Addition and subtraction of numbers

Theory
Character storage

• Computer stores binary numbers, so how character ‘A’ and ‘$’ are stored.
• Computer uses character encoding scheme that translate numbers into letters.
• Well-known scheme is ASCII (American Standard code for Information Interchange)
• ASCII is 7-bit code with range 0 to 127.
Signed Numbers

• Signed byte uses only 7-bits for its magnitude.


• Highest bit is reserved for the sign, where 0 indicates positive and 1 indicates negative.
Example:

11110110 = -10

00001010 = + 10

Two’s Complement Notation

• Negative numbers use Two’s complement representation.


• Removes the need for separate digital circuits to handle both addition and subtraction.
Example:
A – B = A + (-B)

To find Twos complement, toggle all bits and add 1.

00000001 = + 1

11111110 (toggle all bits)

+ 1 (add 1)
--------------------

11111111 = - 1

Example:

00001010 = + 10

11110101 (toggle all bits)

+ 1 (add 1)
-------------------

11110110 = - 10
Activity 4.1:
Show the working of following instruction by taking the two’s complement
• 9–6 + =

• 146 – 9 + =

• 5008 – 5007 _ + =

Two’s Complement of Hexadecimal

• To form the two’s complement of a hexadecimal integer, reverse all bits and add 1
• Easy way to reverse the bits of a hexadecimal digit is to subtract the digit from
15. Example:
6A3D ➔ 95C2 + 1 ➔ 95C3

Activity 4.2:

8C35 --> +1=

AF10 --> +1 =

BCAF – ABCAC =--> + =

AF16 – F8 = -> + =

Activity 4.3: Addition of two single digits numbers


org 100h

.data

Num1 db 0
Num2 db 0
msgNum1 db "Enter the 1st No: $"
msgNum2 db 10,13,"Enter the 2nd No:
$" msgAns db 10,13,"The answer is:
$"
.code
;========================================

main proc

mov ax, @data


mov ds, ax
mov dx,offset msgNum1
mov ah, 09h
int 21h
mov ah, 1 ; accept 1 char from keyboard
int 21h
sub al,30h ; convert to number
mov Num1,al

;=======================================
mov ax, @data
mov ds, ax
mov dx,offset msgNum2
mov ah, 09h
int 21h
mov ah, 1 ;accept 1 char from keyboard
int 21h
sub al,30h ;convert to number
mov Num2,al
;++++++++++++++++++++++++++++++++++++++++++

;ADD Num1,Num2 is illegal

mov bh, Num1


add bh, Num2
add bh, 30h ;convert back to ASCII equiv
mov ax, @data
mov ds, ax
mov dx,offset msgAns ;some message
mov ah, 09h
int 21h

mov dl,bh
mov ah,2 ;print answer
int 21h
mov ah,00h ;pause.... resume when press any key

int 16h

main endp

ret

Activity 4.4: Addition of two multi-digits numbers


include emu8086.inc ;include library

.data num1
dw 0

num2 dw 0
; get the multi-digit signed number from the keyboard, and store the
; result in cx register:
call scan_num ; Get first number
mov num1, cx ; store first number:
call scan_num ; Get second number
mov num2, cx ; store second number:
mov ax, num1 ; Cannot add two memory variables
add ax, num2 ; add num2 in ax and store result in ax
call print_num ; print ax value.
DEFINE_PRINT_NUM ; used by print_num

proc DEFINE_PRINT_NUM_UNS ; used by

print_num proc DEFINE_SCAN_NUM ; used by

scan_num proc END

LAB TASKS
Task # 01

A. Complete the blanks in Activities 4.1 and 4.2


B. Run the sample programs in activity 4.3 and 4.4 and understand / observe the output

TASK#02

Write a program which solve the following

equation Z=A-B+C

Where A, B, C are the inputs (single digit numeric value from 0 to 5) and Z is output

Sample Output:
Enter value of A? 5
Enter value of B? 4
Enter value of C? 3
Value of Z is 4

TASK # 03

Write a program that reads five unsigned integers from user and display sum of those five integers on
the screen.

Sample Output:

Enter 1st value?


10 Enter 2nd
value? 11
Enter 3rd value? 5 Enter 4th value? 6
Enter 5th value? 8 Enter 6th value? 9
Sum of all numbers is 49

TASK # 04

Create an assembly program which take a single digit character (1 to 6 )as input from user your program
should display the next two consecutive positive integers and previous one integer.

Sample output:

Enter a numeric character between 1 – 6 ??? 3


integer - > previous= 2
integer -> next = 4
integer - > next - > next = 5

TASK # 05

Create a program which take two numbers from the user, your program should swap the values of
both the numbers and display on the screen.
note : you cannot use any extra variable in .data portion

Sample Output:

Enter var1 value: 15


Enter var2 value: 13
After swapping
value of var1 is 13
value of var2 is 15

You might also like