COA Lab Manual
COA Lab Manual
COA Lab Manual
LAB MANUAL
Computer Organization & Architecture Lab
Subject Code: ETCS 250
SEMESTER - IV
Prepared By:
Garima Mehra
Assistant Professor
Department of Computer Science & Engineering
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 1
Computer Organization & Architecture Lab Manual
Syllabus
UNIT- I
Computer Arithmetic and Register transfer language:
Unsigned notation, signed notation, binary coded decimal, floating point numbers, IEEE 754 floating point standard,
Micro-operation, Bus and Memory Transfers, Bus Architecture, Bus Arbitration, Arithmetic Logic, Shift Micro
operation, Arithmetic Logic Shift Unit.
[T1,T2][No. of hrs. 11]
UNIT- II
Instruction set architecture & computer organization:
Levels of programming languages, assembly language instructions, 8085 instruction set architecture, Instruction
Codes, Computer Registers, Computer Instructions, Timing & Control, Instruction Cycle, Memory Reference
Instructions, Input-Output and Interrupts
[T1,T2][No. of hrs. 11]
UNIT- III
Control Design:
Instruction sequencing & interpretation, Hardwired & Micro Programmed (Control Unit), Micrprogrammed
computers, Microcoded CPU: Pentium processor. Specifying a CPU, Design & implementation of simple CPU,
General Register Organization, Stack Organization, Instruction Formats, Addressing Modes, Internal architecture of
8085 microprocessor.
[T1,T2][No. of hrs. 11]
UNIT- IV
Memory & Input/Output organization: Memory Technology, Main Memory (RAM and ROM Chips), Virtual
memory, High-speed memories
Asynchronous Data Transfers, Programmed I/O, interrupts, Direct memory Access, Serial communication, UARTs,
RS-232-C & RS-422 standard
[T1,T2][No. of hrs. 11]
Text Books:
[T1] J. D. Carpinelli, “Computer Systems Organization and Architecture”, Pearson Education, 2006.
[T2] J. P. Hayes, “Computer Architecture and Organization”, McGraw Hill, 1988.
Reference Books:
[R1] J. L Hennessy and D. A. Patterson, “Computer Architecture: A quantitative approach”, Morgon Kauffman,
1992.
[R2] W. Stallings, “Computer organization and Architecture”, PHI, 7th ed, 2005.
[R3] B. Parhami, “Computer Architecture: From Microprocessors to Supercomputers”, Oxford University press,
2006.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 2
Computer Organization & Architecture Lab Manual
Hardware Requirements:
operating system
d) 2 GB RAM Cabinet
e) 320 GB HDD
f) Three-button mouse
g) Keyboard
i) Laser Printer
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 3
Computer Organization & Architecture Lab Manual
An 8085 simulator on Java platform. Supports all 8085 interrupts and instructions. User enters
8085 assembly language programs, whose simulation is performed by the software. For
academic purposes only.
Features
Simulates 8085 Interrupts - INTR, RST 7.5, RST 6.5, RST 5.5, TRAP
An easy-to-use GUI
STEP 1: click onto icon of simulator, window will open on the screen
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 4
Computer Organization & Architecture Lab Manual
Step 3: Press Ctrl+S button to save the program. A wizard will open, write program name
and press save button to save program.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 5
Computer Organization & Architecture Lab Manual
Step 4: Press the green triangle button in the top ribbon, to run the program.
Simultaneously the values in Registers will also change.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 6
Computer Organization & Architecture Lab Manual
Lab Assignment – 1
1. Introduction to 8085
The Intel 8085 ("eighty-eighty-five") is an 8-bit microprocessor produced by Intel and
introduced in 1976.[2] It is a software-binary compatible with the more-famous Intel 8080 with
only two minor instructions added to support its added interrupt and serial input/output features.
However, it requires less support circuitry, allowing simpler and less
expensive microcomputer systems to be built.
The "5" in the part number highlighted the fact that the 8085 uses a single +5-volt (V) power
supply by using depletion-mode transistors, rather than requiring the +5 V, −5 V and +12 V
supplies needed by the 8080. This capability matched that of the competing Z80, a popular 8080-
derived CPU introduced the year before. These processors could be used in computers running
the CP/M operating system.
The 8085 is supplied in a 40-pin DIP package. To maximise the functions on the available pins,
the 8085 uses a multiplexed address/data (AD^0-AD^7) bus. However, an 8085 circuit requires
an 8-bit address latch, so Intel manufactured several support chips with an address latch built in.
These include the 8755, with an address latch, 2 KB of EPROM and 16 I/O pins, and the 8155
with 256 bytes of RAM, 22 I/O pins and a 14-bit programmable timer/counter. The multiplexed
address/data bus reduced the number of PCB tracks between the 8085 and such memory and I/O
chips.
Both the 8080 and the 8085 were eclipsed by the Zilog Z80 for desktop computers, which took
over most of the CP/M computer market, as well as a share of the booming home-
computer market in the early-to-mid-1980s.
The 8085 had a long life as a controller, no doubt thanks to its built-in serial I/O and 5 prioritized
interrupts, arguably microcontroller-like features that the Z80 CPU did not have. Once designed
into such products as the DECtape II controller and the VT102 video terminal in the late 1970s,
the 8085 served for new production throughout the lifetime of those products. This was typically
longer than the product life of desktop computers.
2. Features of 8085
Page 7
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 8
Computer Organization & Architecture Lab Manual
S Z AC P CY
Instruction register and decoder
It is an 8-bit register. When an instruction is fetched from memory then it is stored in the
Instruction register. Instruction decoder decodes the information present in the Instruction
register.
Timing and control unit
It provides timing and control signal to the microprocessor to perform operations. Following are
the timing and control signals, which control external and internal circuits −
Control Signals: READY, RD’, WR’, ALE
Status Signals: S0, S1, IO/M’
DMA Signals: HOLD, HLDA
RESET Signals: RESET IN, RESET OUT
Interrupt control
As the name suggests it controls the interrupts during a process. When a microprocessor is
executing a main program and whenever an interrupt occurs, the microprocessor shifts the
control from the main program to process the incoming request. After the request is completed,
the control goes back to the main program.
There are 5 interrupt signals in 8085 microprocessor: INTR, RST 7.5, RST 6.5, RST 5.5,
TRAP.
Serial Input/output control
It controls the serial data communication by using these two instructions: SID (Serial input
data) and SOD (Serial output data).
Address buffer and address-data buffer
The content stored in the stack pointer and program counter is loaded into the address buffer
and address-data buffer to communicate with the CPU. The memory and I/O chips are
connected to these buses; the CPU can exchange the desired data with the memory and I/O
chips.
Address bus and data bus
Data bus carries the data to be stored. It is bidirectional, whereas address bus carries the location
to where it should be stored and it is unidirectional. It is used to transfer the data & Address I/O
devices.
8085 Architecture
We have tried to depict the architecture of 8085 with this following image −
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 9
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 10
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 11
Computer Organization & Architecture Lab Manual
ALE − It is a positive going pulse generated when a new operation is started by the
microprocessor. When the pulse goes high, it indicates address. When the pulse goes
down it indicates data.
Three status signals are IO/M, S0 & S1.
IO/M
This signal is used to differentiate between IO and Memory operations, i.e. when it is high
indicates IO operation and when it is low then it indicates memory operation.
S1 & S0
These signals are used to identify the type of current operation.
Power supply
There are 2 power supply signals − VCC & VSS. VCC indicates +5v power supply and VSS
indicates ground signal.
Clock signals
There are 3 clock signals, i.e. X1, X2, CLK OUT.
X1, X2 − A crystal (RC, LC N/W) is connected at these two pins and is used to set
frequency of the internal clock generator. This frequency is internally divided by 2.
CLK OUT − This signal is used as the system clock for devices connected with the
microprocessor.
Interrupts & externally initiated signals
Interrupts are the signals generated by external devices to request the microprocessor to perform
a task. There are 5 interrupt signals, i.e. TRAP, RST 7.5, RST 6.5, RST 5.5, and INTR. We will
discuss interrupts in detail in interrupts section.
INTA − It is an interrupt acknowledgment signal.
RESET IN − This signal is used to reset the microprocessor by setting the program
counter to zero.
RESET OUT − This signal is used to reset all the connected devices when the
microprocessor is reset.
READY − This signal indicates that the device is ready to send or receive data. If
READY is low, then the CPU has to wait for READY to go high.
HOLD − This signal indicates that another master is requesting the use of the address
and data buses.
HLDA (HOLD Acknowledge) − It indicates that the CPU has received the HOLD
request and it will relinquish the bus in the next clock cycle. HLDA is set to low after
the HOLD signal is removed.
Serial I/O signals
There are 2 serial signals, i.e. SID and SOD and these signals are used for serial
communication.
SOD (Serial output data line) − The output SOD is set/reset as specified by the SIM
instruction.
SID (Serial input data line) − The data on this line is loaded into accumulator whenever a
RIM instruction is executed.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 12
Computer Organization & Architecture Lab Manual
Page 13
Computer Organization & Architecture Lab Manual
Note − NTA is not an interrupt, it is used by the microprocessor for sending acknowledgement.
TRAP has the highest priority, then RST7.5 and so on.
Interrupt Service Routine (ISR)
A small program or a routine that when executed, services the corresponding interrupting source
is called an ISR.
TRAP
It is a non-maskable interrupt, having the highest priority among all interrupts. Bydefault, it is
enabled until it gets acknowledged. In case of failure, it executes as ISR and sends the data to
backup memory. This interrupt transfers the control to the location 0024H.
RST7.5
It is a maskable interrupt, having the second highest priority among all interrupts. When this
interrupt is executed, the processor saves the content of the PC register into the stack and
branches to 003CH address.
RST 6.5
It is a maskable interrupt, having the third highest priority among all interrupts. When this
interrupt is executed, the processor saves the content of the PC register into the stack and
branches to 0034H address.
RST 5.5
It is a maskable interrupt. When this interrupt is executed, the processor saves the content of the
PC register into the stack and branches to 002CH address.
INTR
It is a maskable interrupt, having the lowest priority among all interrupts. It can be disabled by
resetting the microprocessor.
When INTR signal goes high, the following events can occur −
The microprocessor checks the status of INTR signal during the execution of each
instruction.
When the INTR signal is high, then the microprocessor completes its current instruction
and sends active low interrupt acknowledge signal.
When instructions are received, then the microprocessor saves the address of the next
instruction on stack and executes the received instruction.
6. Instruction format
An instruction is a command to the microprocessor to perform a given task on a specified
data. Each instruction has two parts: one is task to be performed, called the operation code
(opcode), and the second is the data to be operated on, called the operand. The operand (or
data) can be specified in various ways. It may include 8-bit (or 16-bit) data, an internal
register, a memory location, or 8-bit (or 16-bit) address. In some instructions, the operand is
implicit.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 14
Computer Organization & Architecture Lab Manual
In the 8085, "byte" and "word" are synonymous because it is an 8-bit microprocessor. However,
instructions are commonly referred to in terms of bytes rather than words.
1 One-Byte Instructions : A 1-byte instruction includes the opcode and operand in the same
byte. Operand(s) are internal register and are coded into the instruction
These instructions are 1-byte instructions performing three different tasks. In the first instruction,
both operand registers are specified. In the second instruction, the operand B is specified and the
accumulator is assumed. Similarly, in the third instruction, the accumulator is assumed to be the
implicit operand. These instructions are stored in 8- bit binary format in memory; each requires
one memory location.
MOV rd, rs
Coded as 01111000 = 78H = 170 octal (octal was used extensively in instruction design of such
processors).
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 15
Computer Organization & Architecture Lab Manual
ADD r
AßA+r
2 Two-Byte Instructions: In a two-byte instruction, the first byte specifies the operation code
and the second byte specifies the operand. Source operand is a data byte immediately following
the opcode. For example:
r ß data
Example: MVI A,30H coded as 3EH 30H as two contiguous bytes.
This is an example of immediate addressing.
ADI data
A ß A + data
3 Three-Byte Instructions: In a three-byte instruction, the first byte specifies the opcode, and
the following two bytes specify the 16-bit address. Note that the second byte is the low-order
address and the third byte is the high-order address.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 16
Computer Organization & Architecture Lab Manual
LDA addr
Example: LDA 2134H coded as 3AH 34H 21H. This is also an example of direct addressing.
NOP none No operation No operation is performed. The instruction is fetched and decoded.
However no operation is executed.
Example: NOP
HLT none Halt and enter The CPU finishes executing the current instruction and halts any further
wait state execution. An interrupt or reset is necessary to exit from the halt state.
Example: HLT
DI none Disable interrupts The interrupt enable flip-flop is reset and all the interrupts except the
TRAP are disabled. No flags are affected.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 17
Computer Organization & Architecture Lab Manual
Example: DI
EI none Enable interrupts The interrupt enable flip-flop is set and all interrupts are enabled. No
flags are affected. After a system reset or the acknowledgement of an
interrupt, the interrupt enable flipflop is reset, thus disabling the
interrupts. This instruction is
necessary to reenable the interrupts (except TRAP).
Example: EI
RIM none Read interrupt This is a multipurpose instruction used to read the status of interrupts
mas 7.5, 6.5, 5.5 and read serial data input bit. The instruction loads eight
bits in the accumulator with the following interpretations.
Example: RIM
SIM none Set interrupt This is a multipurpose instruction and used to implement the 8085
mask interrupts 7.5, 6.5, 5.5, and serial data output. The instruction interprets
the accumulator contents as follows.
Example: SIM
CMP R Compare register The contents of the operand (register or memory) are M compared
M or memory with with the contents of the accumulator. Both contents are preserved .
accumulator The result of the comparison is shown by setting the flags of the PSW
as follows:
if (A) < (reg/mem): carry flag is set
if (A) = (reg/mem): zero flag is set
if (A) > (reg/mem): carry and zero flags are reset
Example: CMP B or CMP M
CPI 8-bit Compare The second byte (8-bit data) is compared with the contents of the
data immediate with accumulator. The values being compared remain unchanged. The
accumulator result of the comparison is shown by setting the flags of the PSW as
follows:
if (A) < data: carry flag is set
if (A) = data: zero flag is set
if (A) > data: carry and zero flags are reset
Example: CPI 89H
ANA R Logical AND The contents of the accumulator are logically ANDed with M the
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 18
Computer Organization & Architecture Lab Manual
M register or memory contents of the operand (register or memory), and the result is placed
with accumulator in the accumulator. If the operand is a memory location, its address is
specified by the contents of HL registers. S, Z, P are modified to
reflect the result of the operation. CY is reset. AC is set.
Example: ANA B or ANA M
ANI 8-bit Logical AND The contents of the accumulator are logically ANDed with the
data immediate with 8-bit data (operand) and the result is placed in the
accumulator accumulator. S, Z, P are modified to reflect the result of the
operation. CY is reset. AC is set.
Example: ANI 86H
XRA R Exclusive OR The contents of the accumulator are Exclusive ORed with M the
M register or memory contents of the operand (register or memory), and the result is placed
with accumulator in the accumulator. If the operand is a memory location, its address is
specified by the contents of HL registers. S, Z, P are modified to
reflect the result of the operation. CY and AC are reset.
Example: XRA B or XRA M
XRI 8-bit Exclusive OR The contents of the accumulator are Exclusive ORed with the 8-bit
data immediate with data (operand) and the result is placed in the accumulator. S, Z, P are
accumulator modified to reflect the result of the operation. CY and AC are reset.
Example: XRI 86H
ORA R Logical OR The contents of the accumulator are logically ORed with M the
M register or memory contents of the operand (register or memory), and the result is placed
with accumulator in the accumulator. If the operand is a memory location, its address is
specified by the contents of HL registers. S, Z, P are modified to
reflect the result of the operation. CY and AC are reset.
Example: ORA B or ORA M
ORI 8-bit Logical OR The contents of the accumulator are logically ORed with the 8-bit
data immediate with data (operand) and the result is placed in the accumulator. S, Z, P are
accumulator modified to reflect the result of the operation. CY and AC are reset.
Example: ORI 86H
RLC none Rotate Each binary bit of the accumulator is rotated left by one position. Bit
accumulator left D7 is placed in the position of D0 as well as in the Carry flag. CY is
modified according to bit D7. S, Z, P, AC are not affected.
Example: RLC
RRC none Rotate Each binary bit of the accumulator is rotated right by one position. Bit
accumulator right D0 is placed in the position of D7 as well as in the Carry flag. CY is
modified according to bit D0. S, Z, P, AC are not affected.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 19
Computer Organization & Architecture Lab Manual
Example: RRC
RAL none Rotate Each binary bit of the accumulator is rotated left by one position
accumulator left through the Carry flag. Bit D7 is placed in the Carry flag, and the
through carry Carry flag is placed in the least significant position D0. CY is
modified according to bit D7. S, Z, P, AC are not affected.
Example: RAL
RAR none Rotate Each binary bit of the accumulator is rotated right by one position
accumulator right through the Carry flag. Bit D0 is placed in the Carry flag, and the
through carry Carry flag is placed in the most significant position D7. CY is
modified according to bit D0. S, Z, P, AC are not affected.
Example: RAR
CMA none Complement The contents of the accumulator are complemented. No flags are
accumulator affected.
Example: CMA
CMC none Complement carry The Carry flag is complemented. No other flags are affected.
Example: CMC
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 20
Computer Organization & Architecture Lab Manual
Jump on
JP S=0
positive
JM Jump on minus S=1
JZ Jump on zero Z=1
JNZ Jump on no zero Z = 0
Jump on parity
JPE P=1
even
Jump on parity
JPO P=0
odd
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 21
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 22
Computer Organization & Architecture Lab Manual
RST 2 0010H
RST 3 0018H
RST 4 0020H
RST 5 0028H
RST 6 0030H
RST 7 0038H
The 8085 has four additional
interrupts and these interrupts
generate RST instructions internally
and thus do not require any external
hardware. These instructions and
their Restart addresses are:
Restart
Interrupt
Address
TRAP 0024H
RST 5.5 002CH
RST 6.5 0034H
RST 7.5 003CH
ADD R Add register or The contents of the operand (register or memory) are added to
M memory, to the contents of the accumulator and the result is stored in the
accumulator accumulator. If the operand is a memory location, its location is
specified by the contents of the HL registers. All flags are
modified to reflect the result of the addition.
Example: ADD B or ADD M
ADC R Add register to The contents of the operand (register or memory) and M the
M accumulator with Carry flag are added to the contents of the accumulator and the
carry result is stored in the accumulator. If the operand is a memory
location, its location is specified by the contents of the HL
registers. All flags are modified to reflect the result of the
addition.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 23
Computer Organization & Architecture Lab Manual
ADI 8-bit data Add immediate to The 8-bit data (operand) is added to the contents of the
accumulator accumulator and the result is stored in the accumulator. All flags
are modified to reflect the result of the addition.
Example: ADI 45H
ACI 8-bit data Add immediate to The 8-bit data (operand) and the Carry flag are added to the
accumulator with contents of the accumulator and the result is stored in the
carry accumulator. All flags are modified to reflect the result of the
addition.
Example: ACI 45H
LXI Reg. pair, Load register pair The instruction loads 16-bit data in the register pair designated in
16-bit data immediate the operand.
Example: LXI H, 2034H or LXI H, XYZ
DAD Reg. pair Add register pair The 16-bit contents of the specified register pair are added to the
to H and L contents of the HL register and the sum is stored in the HL
registers register. The contents of the source register pair are not altered. If
the result is larger than 16 bits, the CY flag is set. No other flags
are affected.
Example: DAD H
SUB R Subtract register or The contents of the operand (register or memory ) are subtracted
M memory from from the contents of the accumulator, and the result is stored in
accumulator the accumulator. If the operand is a memory location, its location
is specified by the contents of the HL registers. All flags are
modified to reflect the result of the subtraction.
Example: SUB B or SUB M
SBB R Subtract source The contents of the operand (register or memory ) and M the
M and borrow from Borrow flag are subtracted from the contents of the accumulator
accumulator and the result is placed in the accumulator. If the operand is a
memory location, its location is specified by the contents of the
HL registers. All flags are modified to reflect the result of the
subtraction.
Example: SBB B or SBB M
SUI 8-bit data Subtract The 8-bit data (operand) is subtracted from the contents of the
immediate from accumulator and the result is stored in the accumulator. All flags
accumulator are modified to reflect the result of the subtraction.
Example: SUI 45H
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 24
Computer Organization & Architecture Lab Manual
SBI 8-bit data Subtract The contents of register H are exchanged with the contents of
immediate from register D, and the contents of register L are exchanged with the
accumulator with contents of register E.
borrow Example: XCHG
INR R Increment register The contents of the designated register or memory) are
M or memory by 1 incremented by 1 and the result is stored in the same place. If the
operand is a memory location, its location is specified by the
contents of the HL registers.
Example: INR B or INR M
INX R Increment register The contents of the designated register pair are incremented by 1
pair by 1 and the result is stored in the same place.
Example: INX H
DCR R Decrement register The contents of the designated register or memory are M
M or memory by 1 decremented by 1 and the result is stored in the same place. If the
operand is a memory location, its location is specified by the
contents of the HL registers.
Example: DCR B or DCR M
DCX R Decrement register The contents of the designated register pair are decremented by 1
pair by 1 and the result is stored in the same place.
Example: DCX H
DAA none Decimal adjust The contents of the accumulator are changed from a binary value
accumulator to two 4-bit binary coded decimal (BCD) digits. This is the only
instruction that uses the auxiliary flag to perform the binary to
BCD conversion, and the conversion procedure is described
below. S, Z, AC, P, CY flags are altered to reflect the results of
the operation.
If the value of the low-order 4-bits in the accumulator is greater
than 9 or if AC flag is set, the instruction adds 6 to the low-order
four bits.
If the value of the high-order 4-bits in the accumulator is greater
than 9 or if the Carry flag is set, the instruction adds 6 to the
high-order four bits.
Example: DAA
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 25
Computer Organization & Architecture Lab Manual
MOV Rd, Rs Copy from source(Rs) This instruction copies the contents of the source register into the
M, Rs to destination(Rd) destination register; the contents of the source register are not
Rd, M altered. If one of the operands is a memory location, its location
is specified by the contents of the HL registers.
Example: MOV B, C or MOV B, M
MVI Rd, data Move immediate 8-bit The 8-bit data is stored in the destination register or memory. If
M, data the operand is a memory location, its location is specified by the
contents of the HL registers.
Example: MVI B, 57H or MVI M, 57H
LDA 16-bit Load accumulator The contents of a memory location, specified by a 16-bit address
address in the operand, are copied to the accumulator. The contents of the
source are not altered.
Example: LDA 2034H
LDAX B/D Reg. Load accumulator The contents of the designated register pair point to a memory
pair indirect location. This instruction copies the contents of that memory
location into the accumulator. The contents of either the register
pair or the memory location are not altered.
Example: LDAX B
LXI Reg. pair, Load register pair The instruction loads 16-bit data in the register pair designated in
16-bit data immediate the operand.
Example: LXI H, 2034H or LXI H, XYZ
LHLD 16-bit Load H and L The instruction copies the contents of the memory location
address registers direct pointed out by the 16-bit address into register L and copies the
contents of the next memory location into register H. The
contents of source memory locations are not altered.
Example: LHLD 2040H
STA 16-bit 16-bit address The contents of the accumulator are copied into the memory
address location specified by the operand. This is a 3-byte instruction, the
second byte specifies the low-order address and the third byte
specifies the high-order address.
Example: STA 4350H
STAX Reg. pair Store accumulator The contents of the accumulator are copied into the memory
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 26
Computer Organization & Architecture Lab Manual
SHLD 16-bit Store H and L The contents of register L are stored into the memory location
address registers direct specified by the 16-bit address in the operand and the contents of
H register are stored into the next memory location by
incrementing the operand. The contents of registers HL are not
altered. This is a 3-byte instruction, the second byte specifies the
low-order address and the third byte specifies the high-order
address.
Example: SHLD 2470H
XCHG none Exchange H and L The contents of register H are exchanged with the contents of
with D and E register D, and the contents of register L are exchanged with the
contents of register E.
Example: XCHG
SPHL none Copy H and L The instruction loads the contents of the H and L registers into
registers to the stack the stack pointer register, the contents of the H register provide
pointer the high-order address and the contents of the L register provide
the low-order address. The contents of the H
and L registers are not altered.
Example: SPHL
XTHL none Exchange H and L The contents of the L register are exchanged with the stack
with top of stack location pointed out by the contents of the stack pointer register.
The contents of the H register are exchanged with the next stack
location (SP+1); however, the contents of the stack pointer
register are not altered.
Example: XTHL
PUSH Reg. pair Push register pair The contents of the register pair designated in the operand are
onto stack copied onto the stack in the following sequence. The stack
pointer register is decremented and the contents of the highorder
register (B, D, H, A) are copied into that location. The stack
pointer register is decremented again and the contents of the low-
order register (C, E, L, flags) are copied to that location.
Example: PUSH B or PUSH A
POP Reg. pair Pop off stack to The contents of the memory location pointed out by the stack
register pair pointer register are copied to the low-order register (C, E, L,
status flags) of the operand. The stack pointer is incremented by
1 and the contents of that memory location are copied to the
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 27
Computer Organization & Architecture Lab Manual
OUT 8-bit port Output data from The contents of the accumulator are copied into the I/O port
address accumulator to a port specified by the operand.
with 8-bit address Example: OUT F8H
IN 8-bit port Input data to The contents of the input port designated in the operand are read
address accumulator from a and loaded into the accumulator.
port with 8-bit Example: IN 8CH
address
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 28
Computer Organization & Architecture Lab Manual
Lab Assignment – 2
Objective: Write a program to add two hexadecimal numbers 23H & 84H and store the result in
a register.
Example –
Algorithm –
1. Load the first number from memory location 2050 to accumualtor.
2. Move the content of accumulator to register H.
3. Load the second number from memory location 2051 to accumaltor.
4. Then add the content of register B and accumulator using “ADD” instruction and storing
result at 3050
5. The carry generated is recovered using “ADC” command and is stored at memory location
3051
Program –
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 29
Computer Organization & Architecture Lab Manual
200E HLT
Explanation –
1. LDA 2050 moves the contents of 2050 memory location to the accumulator.
2. MOV H, A copies contents of Accumulator to register H to A
3. LDA 2051 moves the contents of 2051 memory location to the accumulator.
4. ADD H adds contents of A (Accumulator) and H register (F9). The result is stored in A
itself. For all arithmetic instructions A is by default an operand and A stores the
result as well
5. MOV L, A copies contents of A (34) to L
6. MVI A 00 moves immediate data (i.e., 00) to A
7. ADC A adds contents of A(00), contents of register specified (i.e A) and carry (1). As
ADC is also an arithmetic operation, A is by default an operand and A stores the result as
well
8. MOV H, A copies contents of A (01) to H
9. SHLD 3050 moves the contents of L register (34) in 3050 memory location and contents of
H register (01) in 3051 memory location
10. HLT stops executing the program and halts any further execution
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 30
Computer Organization & Architecture Lab Manual
Lab Assignment – 3
Objective: Write a program to subtract two hexadecimal numbers 23H & 84H and store the
result in a register.
Example –
Algorithm –
1. Load 00 in a register C (for borrow)
2. Load two 8-bit number from memory into registers
3. Move one number to accumulator
4. Subtract the second number with accumulator
5. If borrow is not equal to 1, go to step 7
6. Increment register for borrow by 1
7. Store accumulator content in memory
8. Move content of register into accumulator
9. Store content of accumulator in other memory location
10. Stop
Program –
MEMORY MNEMONICS OPERANDS COMMENT
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 31
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 32
Computer Organization & Architecture Lab Manual
Lab Assignment – 4
Example –
Algorithm –
1. Load the data from memory 3000 into A (accumulator)
2. Complement content of accumulator
3. Store content of accumulator in memory 3001 (1’s complement)
4. Add 01 to Accumulator content
5. Store content of accumulator in memory 3002 (2’s complement)
6. Stop
Program –
MEMORY MNEMONICS OPERANDS COMMENT
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 33
Computer Organization & Architecture Lab Manual
Explanation –
1. A is an 8-bit accumulator which is used to load and store the data directly
2. LDA is used to load accumulator direct using 16-bit address (3 Byte instruction)
3. CMA is used to complement content of accumulator (1 Byte instruction)
4. STA is used to store accumulator direct using 16-bit address (3 Byte instruction)
5. ADI is used to add data into accumulator immediately (2 Byte instruction)
6. HLT is used to halt the program
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 34
Computer Organization & Architecture Lab Manual
Lab Assignment – 5
Example –
Algorithm –
1. We are taking adding the number 43 seven(7) times in this example.
2. As the multiplcation of two 8 bit numbers can be maximum of 16 bits so we need
register pair to store the result.
Program –
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 35
Computer Organization & Architecture Lab Manual
2012 HLT
Explanation –
Registers used: A, H, L, C, D, E
1. LHLD 2050 loads content of 2051 in H and content of 2050 in L
2. XCHG exchanges contents of H with D and contents of L with E
3. MOV C, D copies content of D in C
4. MVI D 00 assigns 00 to D
5. LXI H 0000 assigns 00 to H and 00 to L
6. DAD D adds HL and DE and assigns the result to HL
7. DCR C decreaments C by 1
8. JNZ 200A jumps program counter to 200A if zero flag = 0
9. SHLD stores value of H at memory location 3051 and L at 3050
10. HLT stops executing the program and halts any further execution
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 36
Computer Organization & Architecture Lab Manual
Lab Assignment – 6
Assumption –
Starting address of program: 2000
Input memory location: 2050, 2051, 2052, 2053
Output memory location: 2054, 2055, 2056, 2057.
Example –
INPUT:
(2050H) = 04H
(2051H) = 00H
(2052H) = 02H
(2053H) = 00H
OUTPUT:
(2054H) = 02H
(2055H) = 00H
(2056H) = FEH
(2057H) = FFH
Algorithm –
1. Intialise register BC as 0000H for Quotient.
2. Load the divisor in HL pair and save it in DE register pair.
3. Load the dividend in HL pair.
4. Subtract the content of accumulator with E register.
5. Move the content A to C and H to A.
6. Subtract with borrow the content of A with D.
7. Move the value of accumulator to H.
8. If CY=1, goto step 10, otherwise next step.
9. Increment register B and jump to step 4.
10. ADD both contents of DE and HL.
11. Store the remainder in memory.
12. Move the content of C to L & B to H.
13. Store the quotient in memory.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 37
Computer Organization & Architecture Lab Manual
Program –
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 38
Computer Organization & Architecture Lab Manual
Explanation –
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 39
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 40
Computer Organization & Architecture Lab Manual
Lab Assignment – 7
Example –
Input : 04H
Output : 18H
as 04*03*02*01 = 24 in decimal => 18H
Algorithm –
1. Load the data into register B
2. To start multiplication set D to 01H
3. Jump to step 7
4. Decrements B to multiply previous number
5. Jump to step 3 till value of B>0
6. Take memory pointer to next location and store result
7. Load E with contents of B and clear accumulator
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 41
Computer Organization & Architecture Lab Manual
PROGRAM
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 42
Computer Organization & Architecture Lab Manual
JNZ
2105H MULTIPLYLOOP Repeated addition
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 43
Computer Organization & Architecture Lab Manual
Explanation –
1. First set register B with data.
2. Set register D with data by calling MULTIPLY subroutine one time.
3. Decrement B and add D to itself B times by calling MULTIPLY subroutine as 4*3 is
equivalent to 4+4+4 (i.e., 3 times).
4. Repeat the above step till B reaches 0 and then exit the program.
5. The result is obtained in D register which is stored in memory
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 44
Computer Organization & Architecture Lab Manual
Lab Assignment – 8
Example –
Algorithm –
1. Maximum number is stored in B register and minimum in C register
2. Load counter in D register
3. Load starting element in Accumulator, B and C register
4. Compare Accumulator and B register
5. If carry flag is not set then transfer contents of Accumulator to B. Else, compare
Accumulator with C register, if carry flag is set transfer contents of Accumulator to C
6. Decrement D register
7. If D>0 take next element in Accumulator and go to point 4
8. If D=0, store B and C register in memory
9. End of program
Program-
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 45
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 46
Computer Organization & Architecture Lab Manual
Lab Assignment – 9
Example –
Input : Base=>02H
Exponent=>03H
Output :08H
Algorithm –
1. Load the base into register B and exponent into register C.
2. To start multiplication set D to 01H.
3. Jump to step 7.
4. Decrements C.
5. Jump to step 3 till value of C>0.
6. Take memory pointer to next location and store result.
7. Load E with contents of B and clear accumulator.
8. Repeatedly add contents of D to accumulator E times.
9. Store accumulator content to D.
10. Go to step 4.
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 47
Computer Organization & Architecture Lab Manual
Program :
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 48
Computer Organization & Architecture Lab Manual
JNZ
2105H MULTIPLYLOOP Repeated addition
Explanation –
1. Set register B with base and register C with exponent.
2. Set register D with base by calling MULTIPLY subroutine one time.
3. Decrement C and add D to itself B times by calling MULTIPLY subroutine.
4. Repeat the above step till C reaches 0 and then exit the program.
5. The result is obtained in D register which is stored in memory
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 49
Computer Organization & Architecture Lab Manual
Lab Assignment – 10
Example –
Assumption – Ten 8-bit numbers are stored from starting memory location 2050. Value of count
is stored at memory location 3050.
Algorithm –
1. Initialize register H with 20 and register L with 4F so that indirect memory points to
memory location 204F.
2. Initialize register C with 00 and register D with 0A.
3. Increment indirect memory by 1.
4. Store value of M in accumulator A.
5. Check whether the content in A is even or odd by performing AND operation of A with 01.
6. If content of A is 00 after AND operation then number scanned was even, If so then
increment C by 01 else if content of A is 01 after AND operation then number scanned was
odd, If so then decrements D by 01.
7. Check if zero flag is not set i.e. ZF = 0 then jump to step 3 otherwise store value of C at
memory location 3050.
Program –
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 50
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 51
Computer Organization & Architecture Lab Manual
JIMS Engineering Management Technical Campus -Department of Computer Science & Engineering
Page 52