Exchange The Contents of Memory Locations

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

Exchange the contents of memory locations

LDA 2000H : Get the contents of memory location 2000H into accumulator

MOV B, A : Save the contents into B register

LDA 4000H : Get the contents of memory location 4000Hinto accumulator

STA 2000H  : Store the contents of accumulator at address 2000H

MOV A, B : Get the saved contents back into A register

STA 4000H : Store the contents of accumulator at address 4000H

OR

LXI H 2000H : Initialize HL register pair as a pointer to memory location 2000H.

LXI D 4000H : Initialize DE register pair as a pointer to memory location 4000H.

MOV B, M  : Get the contents of memory location 2000H into B register.

LDAX D : Get the contents of memory location 4000H into A register.

MOV M, A : Store the contents of A register into memory location 2000H.

MOV A, B : Copy the contents of B register into accumulator.

STAX D : Store the contents of A register into memory location 4000H.

HLT : Terminate program execution.

2}Add two 8-bit numbers


LXI H 4000H : HL points 4000H

MOV A, M : Get first operand

INX H : HL points 4001H

ADD M : Add second operand


INX H : HL points 4002H

MOV M, A : Store result at 4002H

HLT : Terminate program execution

OR

MVI C, 00 Intialize counter s 00

LDA 4150 Load value to accumulator

MOV B,A Move contents of accumulator to register B

LDA 4150 Load the value to accumulator

ADD B Add the value of register B to A

JNC * Loop Jump on no carry

INR C Increment the value of register C

STA 4152 Store the value of Accumulator(SUM)

MOV A,C Move contents of the register c to Accumulator

STA 4153 Store the value of Accumulator(Carry)

RST Restart
Multiply two 8-bit numbers stored in memory locations 2200H and 2201H

 LDA 2200H

 MOV E, A

 MVI D, 00 : Get the first number in DE register pair

 LDA 2201H

 MOV C, A  : Initialize counter

 LX I H, 0000 H  : Result = 0

 BACK: DAD  D  : Result = result + first number

 DCR C  : Decrement count

 JNZ  BACK  : If count   0 repeat

 SHLD 2300H : Store result

 HLT  : Terminate program execution

Or

MVI D,00
MVI A,00

LXI H,4150

MOV B,M

INX H

MOV C,M

ADD B

JNC Next

INR D

DCR C

JNZ Loop

STA 4152

MOV A,D

STA 4153

RST
Write a program to shift an eight bit data four bits right. Assume data is in register C

 MOV A, C

 RAR

 RAR

 RAR

 RAR

 MOV C, A

 HLT

OR

 MOV A, B

 RAR

 MOV B, A

 MOV A, C

 RAR

 MOV C, A

 HLT

You might also like