Micro Programs
Micro Programs
LDA 2200
MOV C, A ; Initialize counter
SUB A ; sum = 0
LXI H, 2201H ; Initialize pointer
BACK: ADD M ; SUM = SUM + data
INX H ; increment pointer
DCR C ; Decrement counter
JNZ BACK ; if counter 0 repeat
STA 2300H ; store sum
HLT
LDA 2200H
MOV C,A ; Initialize counter
LXI H, 2201H ; Initialize pointer
SUB A ; Sum low = 0
MOV B,A ; Sumhigh = 0
BACK: ADD M ; Sum = sum + data
JNC SKIP
INR B ; Add carry to MSB of SUM
SKIP: INX H ; Increment pointer
DCR C ; Decrement counter
JNZ BACK ; Check if counter 0 repeat
STA 2300H ; Store lower byte
MOV A,B
STA 2301H ; Store higher byte
HLT ; Terminate program execution
1
Problem 4: Block data transfer.
LDA 2200H
MOV E, A
MVI D, 00 ; Get the first number
LDA 2201H
MOV C, A ; Initialize counter
LXI H, 0000H ; 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
2
Problem 7: No of negative numbers in the list of hexadecimal numbers.
LDA 2200H
MOV C, A ; Initialize count
MVI B, 00 ; Negative number = 0
LXI H, 2201H ; Initialize pointer
BACK: MOV A, M ; Get the number
ANI 80H ; Check for MSB
JZ SKIP ; If MSB = 1
INR B ; Increment negative number count
SKIP: INX H ; Increment pointer
DCR C ; Decrement count
JNZ BACK ; If count 0 repeat
MOV A, B
STA 2300H ; Store the result
HLT ; Terminate program execution
LDA 2200H
MOV C, A ; Initialize counter
XRA A ; Maximum = Minimum possible value = 0
LXI H, 2201H ; Initialize pointer
BACK: CMP M ; Is number > maximum
JNC SKIP
MOV A, M ; Yes, replace maximum
SKIP: INX H
DCR C
JNZ BACK
STA 2300H ; Store maximum number
HLT ; Terminate program execution
3
/*Adding the 4 most significant bit to a hexa no*/
; For detail explanation of program refer page no. 169 of book
; Microprocessor And Microcomputer by A. P. Godse
LDA 2201H ; Get the Most significant BCD digit
RLC
RLC
RLC
RLC ; Adjust the position
MOV C, A ; store the partial result
LDA 2200H ; Get the lower BCD digit
ADD C ; Add lower BCD digit
STA 2300H ; Store the result
HLT ; Terminate program execution
LDA 2000H ; Get the contents of memory location 2000H into accumulator
MOV B,A ; save the contents in B register
LDA 2200H ; Get the contents of memory location 2200H into accumulator.
STA 2000H ; Store the contents of accumulator at address 2000H.
MOV A,B ; Get the saved contents back into A register
STA 2200H ; Store the contents of accumulator at address 2200H
HLT ; Terminate program execution
4
/*Separate the digits of a hexa decimal nos and store it in two diff. locations*/
; For detail explanation of program refer page no. 170 of book
; Microprocessor And Microcomputer by A. P. Godse
LDA 2200H ; Get the packed BCD number
ANI F0H ; Mask lower nibble
RRC
RRC
RRC
RRC ; Adjust higher BCD digit as a lower digit
STA 2300H ; Store the partial result
LDA 2200H ; Get the original BCD number
ANI 0FH ; Mask higher nibble
STA 2301H ; Store the result
HLT ; Terminate program execution
/**/
; For detail explanation of program refer page no. 181 of book
; Microprocessor and Microcomputer by A. P. Godse
LXI SP,2400 ; Initialize stack pointer
MVI C, 08H ; Initialize count with 8
BACK: MOV A,B ;
RRC ; Rotate B register contents right
MOV B,A ; Save contents of register B
JNC SKIP ; If no carry skip
MVI A,0C0H
SIM ; If carry, send high on SOD
JMP NEXT
SKIP: MVI A,40H
5
SIM ; If no carry, send low on SOD
NEXT:CALL DELAY ; Wait for specific time
DCR C ; Decrement count by 1
JNZ BACK ; if count = 0, if not repeat
HLT ; Stop program execution
DELAY: LXI D,0001
BACK1: DCX D
MOV A,E
ORA D
JNZ BACK1
RET
/**/
; For detail explanation of program refer page no. 181 of book
; Microprocessor & Microcomputer by A. P. Godse
LXI SP, 27FFH
LXI H, 2000H ; Memory pointer
RIM ; Read SID
ANI 80H ; Check D7 bit of Accumulator
CALL DELAY ; 1/2 bit time delay for stop bit
MVI B, 08H ; Initialize bit counter
MVI D, 00H ; Clear data register
UP1: CALL DELAY ; 1bit time
RIM ; Read SID line
ANI 80 H ; Mask bits B6-B0
ORA D ; OR data bit with previous bits
RRC
MOV D, A ; Store data bit at appropriate position
DCR B
JNZ UP1
RLC ; Shift left to correct result
MOV M, A ; Store result
RIM ; Read stop bit
ANI 80H
CZ ERROR ; If not stop bit call error
HLT ; Terminate program.
DELAY: MVI E,01
BACK1: DCR E
JNZ BACK1
RET
ERROR: MVI A,0FF
RET
6
INX H ; HL Points 2002H
MOV M,A ; Store the lower byte of result at 2002H
MVI A,00 ; Initialize higher byte result with 00H
ADC A ; Add carry in the high byte result
INX H ; HL Points 2003H
MOV M,A ; Store the higher byte of result at 2003H
HLT
8
MOV A, D
STA 2301H ; Store higher byte
HLT ; Terminate program execution
/*store the nos in a memory loc. In the reverse order in another memory loc.*/
; For detail explanation of program refer page no. 191 of book
; Microprocessor And Microcomputer by A. P. Godse
MVI C, 0AH ; Initialize counter
LXI H, 2200H ; Initialize source memory pointer
LXI D, 2309H ; Initialize destination memory pointer
BACK: MOV A, M ; Get byte from source memory block
STAX D ; Store byte in the destination memory block
INX H ; Increment source memory pointer
DCX D ; Decrement destination memory pointer
DCR C ; Decrement counter
JNZ BACK ; If counter 0 repeat
HLT ; Terminate program execution
/*Search for a no in the list if found store address where it is found else store 0000*/
; For detail explanation of program refer page no. 194 of book
; Microprocessor And Microcomputer by A. P. Godse
LXI H,2000H ; Initialize memory pointer
MVI B, 52H ; Initialize counter
BACK: MOV A,M ; Get the number
CMP C ; Compare with the given byte
JZ LAST ; Go last if match occurs
INX H ; Increment memory pointer
DCR B ; Decrement counter
JNZ BACK ; If not zero, repeat
LXI H, 0000H
SHLD 2200H
JMP END ; Store 00 at 2200H and 2201H
LAST: SHLD 2200H ; Store memory address
9
END: HLT ; Stop
/*In a list of 50 nos separate the even nos and store the in different memory loc.*/
; For detail explanation of program refer page no. 199 of book
; Microprocessor And Microcomputer by A. P. Godse
LXI H, 2200H ; Initialize memory pointer1
LXI D, 2300H ; Initialize memory pointer2
MVI C, 32H ; Initialize counter
BACK: MOV A, M ; Get the number
ANI 01H ; Check for even number
JNZ SKIP ; If ODD, don’t store
MOV A, M ; Get the number
STAX D ; Store the number in result list
INX D ; Increment pointer 2
SKIP: INX H ; Increment pointer1
DCR C ; Decrement counter
JNZ BACK ; If not zero, repeat
HLT ; Stop
11
/*convert the set of nos to odd parity if the no is even parity*/
; For detail explanation of program refer page no. 199 of book
; Microprocessor And Microcomputer by A. P. Godse
LXI H, 2040H
MOV C,M ; Counter for character
REPEAT: INX H ; Memory pointer to character
MOV A,M ; Char. in accumulator
ORA A ; ORing with itself to check parity.
JPO PAREVEN
ORI 80H ; If odd parity place even parity in D7(80).
PAREVEN: MOV M,A ; Store converted even parity character.
DCR C ; Decrement counter.
JNZ REPEAT ; If not zero go for next character.
HLT ; Terminate program execution
12
DELAY: LXI D, 0001
BACK1: DCX D
MOV A,E
ORA D
JNZ BACK1
RET
/*Decimal addition*/
; For detail explanation of program refer page no. 135 of book
13
; Microprocessor And Microcomputer by A. P. Godse
LXI H, 2200H ; Initialize pointer
MOV A,M ; Get the first number
INX H ; Increment the pointer
ADD M ; Add two numbers
DAA ; Convert HEX to valid BCD
STA 2300H ; Store the result
HLT ; Terminate program execution
----------------------------------
14