Run the first program
Step1:
Open GNU Sim 8085 this window will open.
Step2:
Start writing the code after start: nop
- mvi a, 12h
- mvi b, 18h
- add b
Step 3:
Click on reset and reset all the registers by clicking on reset all.
Step 4:
Click on the highlighted button to execute the code
Step 5:
Name and save the file.
Step 6:
After this you will see the result of the instructions in the respective registers as seen in the image.
Practise problems
Write andexecute the following codes as mentioned in step 2.
Prob 01: Addition of two numbers
lda var1
mov b,a
lda var2
add b
sta var3
hlt
var1: db 04h
var2: db 09h
var3: db 00h
Prob 02: To add n consecutive numbers
lxi h,var
mov c,m
mvi b,01h
mvi e,00h
mvi a,00h
back: add b
jnc skip
inr e
skip: inr b
dcr c
jnz back
sta result
mov a,e
sta carry
hlt
var: db 0Ah
result: db 00h
carry: db 00h
Prob 03: Count the number of 1’s.
lxi h,var
mvi c,08h;counter
mov a,m
mvi b,00h;count number of 1’s
back: rar
jnc skip
inr b
skip: dcr c
jnz back
mov a,b
sta result
hlt
var: db 19h
result: db 00h
prob 04: Multiply two 8 bit numbers without shifting.
lxi h,
var; multiplicand
mvi d,00h
mov e,m
inx h
mov c,m; multiplier as counter for repeated addition
mvi h,00h
mvi l,00h
back: dad d
dcr c
jnz back
shld result
hlt
var: db 08h
var2: db 07h
result: db 00h
result2: db 00h
Prob 05: Addition of two numbers using lxi.
lxi h,var1
mov a,m
inx h
mov b,m
sub b
inx h
mov m,a
hlt
var1: db 08h
var2: db 03h
var3: db 00h
Prob 06: Division of 8bit number.
lhld var;dividend
lda var2;divisor
mov b,a
mvi c,08h
back: dad h
mov a,h
sub b
jc forward
mov h,a
inr l
forward: dcr c
jnz back
shld var3
hlt
var: db 0ch
var1: db 00h
var2: db 05h
var3: db 00h
var4: db 00h
Prob 07: To find the smallest and largest number from the given series.
lxi h,var
mov c,m ;counter
inx h
dcr c
mov b,m;for largest
mov d,m;for smallest
mov a,m
back: cmp b
jc ahead
mov b,a
ahead: cmp d
jnc ahead2
mov d,a
ahead2: inx h
mov a,m
dcr c
jnz back
inx h
mov m,d
inx h
mov m,b
hlt
var: db 05h
var1: db 02h
var2: db 02h
var3: db 07h
var4: db 0Ah
var5: db 0Ah
smallest: db 00h
largest: db 00h
MVI: – move immediate date to a register or memory location.
Eg: – MVI Rd, #30H (30h is stored in register Rd)
MVI M, #30H(30h is stored in memory location pointed by HL Reg)
mov ——> data movement instruction
lda ——> load accumulator with the contents from memory
5.LXI(Load register pair immediate): – The instruction loads 16-bit data in the register pair designated in the
operand.
Eg: – LXI H, 2034H (2034H is stored in HL pair so that it act as memory pointer)
LXI H, XYZ (address of level XYZ is copied in HL pair)
MVI is a mnemonic, which actually means “Move Immediate”. With this instruction,we can load a register with an 8-bitsor 1-Bytevalue.