0% found this document useful (0 votes)
50 views

Opena, Neil Piolo Tristian L

The document provides an introduction to assembly language programming. It discusses the basic components of a computer system including the CPU, registers, memory, and bus. It describes the different general purpose and special purpose registers in the 8086 CPU. It explains how registers and segments are used to access memory locations. Finally, it introduces the MOV instruction for moving data between registers and memory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Opena, Neil Piolo Tristian L

The document provides an introduction to assembly language programming. It discusses the basic components of a computer system including the CPU, registers, memory, and bus. It describes the different general purpose and special purpose registers in the 8086 CPU. It explains how registers and segments are used to access memory locations. Finally, it introduces the MOV instruction for moving data between registers and memory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

BATANGAS STATE UNIVERSITY BatstateU Alangilan

LABORATORY 01
INTRODUCTION TO ASSEMBLY LANGUAGE

Name: Opena, Neil Piolo Tristian L. Date: 6/23/2021

Year and Section ECE-3302


Subject Code: ECE 415
Subject Description Microprocessor and Microcontroller Systems and Design
Instructor: Engr. Kirk Vincent V. Montinola, ECE
I. OBJECTIVES
1. To familiarize the usage and work-around of the 8086 Emulator.
2. To understand the different instruction set used in assembly language in writing programs for
the Intel 8086.
3. To write assembly codes to read, write, and move data from different registers.
II. DISCUSSIONS
Assembly language is a low level programming language. You need to get some knowledge
about computer structure in order to understand anything. The simple computer model as I see it:

The system bus (shown in yellow) connects the various components of a computer.
The CPU is the heart of the computer, most of computations occur inside the CPU.
RAM is a place to where the programs are loaded in order to be executed.

Inside the CPU

General Purpose Registers


8086 CPU has 8 general purpose registers, each register has its own name:
AX - the accumulator register (divided into AH / AL).
BX - the base address register (divided into BH / BL).

Prepared by: Engr. Kirk Vincent V. Montinola, ECE


BATANGAS STATE UNIVERSITY BatstateU Alangilan

CX - the count register (divided into CH / CL).


DS - the data register (divided into DH / DL).
SI - source index register.
DI - destination index register.
BP - base pointer.
SP - stack pointer

Despite the name of a register, it's the programmer who determines the usage for each general purpose
register. The main purpose of a register is to keep a number (variable). The size of the above registers
is 16 bit, it's something like: 0011000000111001b (in binary form), or 12345 in decimal (human) form.

4 general purpose registers (AX, BX, CX, DX) are made of two separate 8 bit registers, for example if
AX= 0011000000111001b, then AH=00110000b and AL=00111001b. Therefore, when you modify any
of the 8 bit registers 16 bit register is also updated, and vice-versa. The same is for other 3 registers, "H"
is for high and "L" is for low part.

Because registers are located inside the CPU, they are much faster than memory. Accessing a memory
location requires the use of a system bus, so it takes much longer. Accessing data in a register usually
takes no time. Therefore, you should try to keep variables in the registers. Register sets are very small
and most registers have special Purposes which limit their use as variables, but they are still an
excellent place to store temporary data of calculations.

Although it is possible to store any data in the segment registers, this is never a good idea. The
segment registers have a very special purpose - pointing at accessible blocks of memory.

Segment registers work together with general purpose register to access any memory value. For
example if we would like to access memory at the physical address 12345h (hexadecimal), we should set
the DS = 1230h and SI = 0045h. This is good, since this way we can access much more memory than
with a single register that is limited to 16 bit values.
CPU makes a calculation of physical address by multiplying the segment register by 10h and
adding general purpose register to it (1230h * 10h + 45h = 12345h):

The address formed with 2 registers is called an effective address.


By default BX, SI and DI registers work with DS segment register;
BP and SP work with SS segment register.
Other general purpose registers cannot form an effective address!
Also, although BX can form an effective address, BH and BL cannot.

Special Purpose Registers


IP - the instruction pointer. flags register - determines the
current state of the microprocessor.

IP register always works together with CS segment register and it points to currently executing instruction.
Flags register is modified automatically by CPU after mathematical operations, this allows to determine the
type of the result, and to determine conditions to transfer control to other parts of the program. Generally you
cannot access these registers directly, the way you can access AX and other general Generally you cannot
access these registers directly, the way you can access AX and other general

Prepared by: Engr. Kirk Vincent V. Montinola, ECE


BATANGAS STATE UNIVERSITY BatstateU Alangilan

registers, but it is possible to change values of system registers using some tricks that you will learn
a little bit later.

Memory Access
To access memory we can use these four registers: BX, SI, DI, BP.
Combining these registers inside [ ] symbols, we can get different memory locations.
These combinations are supported (addressing modes):

d8 - stays for 8 bit signed immediate displacement (for example: 22, 55h, -1) d16 -
stays for 16 bit signed immediate displacement (for example: 300, 5517h, -259).
Displacement can be a immediate value or offset of a variable, or even both. If there are several
values, assembler evaluates all values and calculates a single immediate value.
Displacement can be inside or outside of the [ ] symbols, assembler generates the same machine code
for both ways.
Displacement is a signed value, so it can be both positive or negative.

Generally the compiler takes care about difference between d8 and d16, and generates the
required machine code.
For example, let's assume that DS = 0100H, BX = 0030H, SI = 0070H.
The following addressing mode: [BX + SI] + 25H
Is calculated by processor to this physical address: 0100H * 10H + 30H + 70H + 25H =
010C5H. or
By default DS segment register is used for all modes except those with BP register, for these SS
segment register is used.
There is an easy way to remember all those possible combinations using this chart.

All valid combinations can be formed by taking only one item from each column or skipping the column
by not taking anything from it. BX and BP never go together. Neither SI and DI do.
Examples of valid addressing modes:
[BX+5] [BX+SI] [DI+BX-4]

Prepared by: Engr. Kirk Vincent V. Montinola, ECE


BATANGAS STATE UNIVERSITY BatstateU Alangilan

The value in segment register (CS, DS, SS, ES) is called a segment, and the value in general
purpose register (BX, SI, DI, BP) is called an offset.
When DS contains value 1234h and SI contains the value 7890h it can be also recorded as 1234:7890.
The physical address will be 1234h * 10h + 7890h = 19BD0h.
If zero is added to a decimal number it is multiplied by 10, however 10h = 16, so
If zero is added to a hexadecimal value, it is multiplied by 16, for example:
7h = 7
70h = 112

In order to say the compiler about data type, these prefixes should be
used: byte ptr - for byte. word ptr - for word (two bytes). for example:

byte ptr [BX] ; byte access.


word ptr [BX] ; word access.

Emu Assembler supports shorter prefixes as well:


b. - for byte ptr
w. - for word ptr

In certain cases the assembler can calculate the data type automatically.

MOV INSTRUCTION
- copies the second operand (source) to the first operand (destination).
- the source operand can be an immediate value, GPR or memory location
- the destination register can be a GPR or memory location
- both operands must be the same size, which can be a byte or a word.

These types of operands are supported:

MOV REG, memory


MOV memory, REG
MOV REG, REG
MOV memory, immediate
MOV REG, immediate

where:
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.
memory: [BX], [BX+SI+7], variable immediate: immediate: 5, -24, 3Fh,
10001101b
For segment registers only these types of MOV are supported:

MOV SREG, memory


MOV memory, SREG
MOV REG, SREG
MOV SREG, REG

where:

Prepared by: Engr. Kirk Vincent V. Montinola, ECE


BATANGAS STATE UNIVERSITY BatstateU Alangilan

SREG: DS, ES, SS, and only as second operand: CS.


REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP. memory:
[BX], [BX+SI+7], variable

The MOV instruction cannot be used to set the value of the CS and IP registers.

A short program that demonstrates the use of MOV instruction:


ORG 100h ; directive requiremd for simple 1-seg .com program.
MOV AX, 0B800h ; set AX to hexadecimal value of B800h.
MOV DS, AX ; copy value of AX to DS.
MOV CL, 'A' ; set CL to ASCII code of 'A', it is 41h.
MOV CH, 1101_1111b ; set CH to binary value.
MOV BX, 15Eh ; set BX to 15Eh.
MOV [BX], CX ; copy contents of CX to memory at B800:015E
RET ; returns to operating system.
Once the above program is typed into the code editor, and [Compile and Emulate] button is pressed
(F5 key)
The emulator window should open with this program loaded, clicking [Single Step] button should
change the register values.
The result of the working program should be:

Actually the above program writes directly to video memory, now we can see that MOV is a very
powerful instruction.

VARIABLES
Variable is a memory location. For a programmer it is much easier to have some value be kept in a
variable named "var1" then at the address 5A73:235B, especially when you have 10 or more variables.
Our compiler supports two types of variables: BYTE and WORD.

Syntax for a variable declaration:

name DB value
name DW value

where:
DB - stays for Define Byte.
DW - stays for Define Word.

Prepared by: Engr. Kirk Vincent V. Montinola, ECE


BATANGAS STATE UNIVERSITY BatstateU Alangilan

name - can be any letter or digit combination, though it 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 - can be any numeric value in any supported numbering system (hexadecimal, binary,
or decimal), or "?" symbol for variables that are not initialized.

Recalling, MOV instruction is used to copy values from source to destination.


Let's see another example with MOV instruction:

1 ORG 100h
2
3 MOV AL, var1
4 MOV BX, var2
5
6 RET ; stops the program.

7 VAR1 DB 7
8 var2 DW 1234h

Questions:
1. Encode in the emulator the above
code: Paste your screenshot code here.

2. What is happens after executing code line 3? on line 4?

The variable is transferred to the specified register. Following execution of the


code, the variable 1 containing “7” from line 3 travels to the register AL,
whereas the variable 2 containing “1234h” from line 4 moves to the register
BX.

3. What happens if code line 8 and 9 will be transferred to line 3 and 4, respectively, offsetting
line 3 and 4

Prepared by: Engr. Kirk Vincent V. Montinola, ECE


BATANGAS STATE UNIVERSITY BatstateU Alangilan
The variable did not perform because it did not move to its designated register.

4. Does Step 2 and 3 has the same output? Or different?

It generates a variety of results, which are displayed in the register. Step 2


moved the variable's content to its appropriate register, however Step 3 did
not.

5. Write a code that will store 4 variables, two are of one byte long and the
other two are 1 word long, to the 4 general purpose registers. Copy paste
your code here.

Screenshot your register values after running all the lines of the code.

7. What are the invalid formats of variables?

When the DB variable is 16 bits, the error “overflowing” appears because the
variable can only support 8 bits. The same goes for the DW, which should be
16 bits.
Prepared by: Engr. Kirk Vincent V. Montinola, ECE
BATANGAS STATE UNIVERSITY BatstateU Alangilan
8. What does MOV function do?

Because it moves data from one location to another, the MOV instruction is the
most crucial command in the 8086. The data in the source is copied to the
destination by MOV.

9. What does [ ] means?

It shows that it can be used to access any element's value in the array. It was
once used to combine many registers in order to acquire different memory
locations.

Prepared by: Engr. Kirk Vincent V. Montinola, ECE

You might also like