Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

DEPARTMENT OF COMPUTER ENGINEERING

University College of Engineering & Technology Bahauddin


Zakariya University, Multan.

Manual Details

Subject Computer Architecture


and Assembly Language
Session 2019 -2023
Pr. Hrs. per 3Hrs. (Pr)
Week

Lab Instructor Engr. Abdul Rehman

Submission Details

Submitted by Muhammad Usama


Saghar

Roll No. 2019-CPE-27

Practical No 05
Practical
Title
 Concept of Data Declaration
 Addition and subtraction of 16-bit numbers using immediate addressing
LAB MANUAL:-05
OBJECTIVE:-

 Concept of Data Declaration


 Addition and subtraction of 16-bit numbers using immediate addressing

DATA DECLARATION:-

The first instruction of first assembly language program was “mov ax , 5”. Here MOV was the
opcode , AX was the destination operand, while 5 was the source operand. The value of 5 in this
case was stored as part of the instruction encoding. In the opcode B80500 , B8 was the opcode
and 0500 was the operand stored immediately afterwards. Such an operand is called an
immediate operand. It is one of the many types of operands available. Writing programs using
just the immediate operand type is difficult. Every reasonable program needs some data in
memory apart from constants. Constants cannot be changed, i.e; they cannot appear as the
destination operand. In fact placing them as destination is meaningless and illegal according to
assembly language syntax. Only registers or data placed in memory can be changed. So real data
is the one stored in the memory, with a very few constants. So there must be a mechanism in
assembly language to store and retrieve data from memory.

The compiler we use supports two types of variables: BYTE & WORD written as “db” for
“define Byte” & “dw” for “define Word”.

name db somevalue

name dw somevalue

name- it can be any letter or digit combination, through is should start with a letter. It’s possible
to declare unnamed variables by not specifying the name (this variable will have an address but
no name).

value- it can be any numeric value in any supported numbering system (hexadecimal , binary or
decimal), or “?” symbol for variables that are not initialized.

As a result, a cell in memory will be reserved containing the desired value in it and it can be
used in a variety of ways. Now we can add variables instead of constants. The other directive is
“define word” or “dw” with the same syntax as “db” but reserving a whole word of 16 bits
instead of a byte. For single byte use db and for two bytes we use dw . To refer to this variable
later in the program, we need the address occupied by this variable. The assembler is there to
help us. We can associate a symbol with any address that we want to remember and use that
symbol in the rest of code.
This is just like variables in a higher level language, where the compiler translates them into
addresses; just the process is hidden from the programmer one level further. Such a symbol
associated to a point in the program is called a label and is written as the label name followed by
a colon.

IMMEDIATE ADRESSING:-

Immediate addressing is so-named because the value to be stored in memory immediately


follows the operation code in memory. That is to say, the instruction itself dictates what value
will be stored in memory.

For example, the instruction:

Mov a, #20h (mov ax, 1234)

This instruction uses immediate Addressing because the Accumulator will be loaded with the
value that immediately follows in this case 20 (hexadecimal).

Immediate Addressing is very fast since the value to be loaded is included in the instruction.
However, since the value to be loaded is fixed at compile-time is not very flexible.

Question:-

Write the above program code for addition and subtraction (16-bit numbers) using immediate
addressing in emu8086and write the values of the following registers after executing each
instruction and verify the values.

ADDITION CODE:-

org 100h

include emu8086.inc

mov ax , 2468

mov bx , 1234

add ax , bx

mov cx , ax

ret
Instruction# AX BX CX

H L H L H L
1 00 00 00 00 00 0B
2 09 A4 00 00 00 0B
3 09 A4 04 D2 00 0B
4 0E 76 04 D2 00 0B
5 0E 76 04 D2 0E 76

SUBTRACTION CODE:-

org 100h

include emu8086.inc

mov ax , 2468

mov bx , 1234

sub ax , bx

mov cx , ax

ret

Instruction# AX BX CX

H L H L H L
1 00 00 00 00 00 0B
2 09 A4 00 00 00 0B
3 09 A4 04 D2 00 0B
4 04 D2 04 D2 00 0B
5 04 D2 04 D2 04 D2

You might also like