Lab 1
Lab 1
Lab 1
CSE331L – Introduction to
Assembly Language
CSE331L_Fall2020
Introduction
In this session, you will be introduced to assembly language
programming and to the emu8086 emulator software. emu8086 will
be used as both an editor and as an assembler for all your assembly
language programming.
Features of 8086
Both ALU & FPU have a very small amount of super-fast private
memory placed right next to them for their exclusive use.
These are called registers
The ALU & FPU store intermediate and final results from their
calculations in these registers
Processed data goes back to the data cache and then to the main
memory from these registers.
Registers are basically the CPU’s own internal memory. They are
used, among other purposes, to store temporary data while
performing calculations. Let’s look at
each one in detail.
CSE331L_Fall2020
The 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).
CX - The Count register (divided into CH / CL).
DX - 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 bits.
Since registers are located inside the CPU, they are much faster
than a 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.
CSE331L_Fall2020
Segment Registers
CS - points at the segment containing the current program.
DS - generally points at the segment where variables are
defined. ES - extra segment register, it's up to a coder to define
its usage. SS - points at the segment containing the stack.
The following table shows the instruction name, the syntax of its
use, and its description. The operands heading refers to the type
of operands that can be used with the instruction along with their
proper order.
CSE331L_Fall2020
Algorithm:
operand1 = operand2
REG, memory memory, Adds two numbers.
REG REG, REG
ADD memory, immediate Algorithm:
REG, immediate operand1=operand1+opera
nd2
CSE331L_Fall2020
TASK 1
Write the following code in emu8086 editor:
org 100H
mov ax,2
mov bx,2
add ax,bx
mov cx,ax
ret
The first line of this program, org 100H, is a necessary requirement for all
assembly programs written in emu8086. You should always start with
this header.
Your program should also always end with the RET instruction. This
instruction basically gives back control of CPU and system
resources back to the operating system. The RET statement will
be used in further classes.
This program basically adds two numbers stored in two separate registers.
The final result is stored in a third register. Assemble this program and run
it. Follow the in- class lecture regarding the use of the emulator and
its various features and debugging techniques.