Mu Pi
Mu Pi
------------------------------------------------------------------
=================================================
LXI H, 2000H ; Load HL with 2000H
MVI M, 52H ; Store 52H in memory location pointed by HL register pair
(2000H)
------------------------------------------------------------------
=================================================
MOV A, L ; Get lower 2 digits of no. 1
ADD E ; Add two lower digits
DAA ; Adjust result to valid BCD
STA 2300H ; Store partial result
MOV A, H ; Get most significant 2 digits of no. 2
ADC D ; Add two most significant digits
DAA ; Adjust result to valid BCD
STA 2301H ; Store partial result
HLT ; Terminate program execution
1
------------------------------------------------------------------ 145 of book
=================================================
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
2
HLT ; Terminate program execution
3
------------------------------------------------------------------ 167 of book
=================================================
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
------------------------------------------------------------------169 of book
=================================================
LDA 2200 H ; Get the number
CMA ; Complement the number
ADI 01H ; Add one in the number
STA 2300H ; Store the result
HLT ; Terminate program execution
4
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
5
------------------------------------------------------------------ 122 of book
=================================================
LXI SP, 2400H
LXI H, 2000H
LXI B, 1020H
CALL SUB
HLT
;Subroutine program :
SUB: PUSH B
PUSH H
LXI B, 4080H
LXI H, 4090H
DAD B
SHLD 2200H
POP H
POP B
RET
6
------------------------------------------------------------------ 181 of book
=================================================
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
7
------------------------------------------------------------------ 185 of book
=================================================
MOV A,C
RAR
RAR
RAR
RAR
MOV C,A
HLT
8
------------------------------------------------------------------ 187 of book
=================================================
LDA 2200H
MOV C, A ; Initialize counter
MVI B, 00H ; sum = 0
LXI H, 2201H ; Initialize pointer
BACK: MOV A, M ; Get the number
ANI, 01H ; Mask Bit1 to Bit7
JNZ SKIP ; Don’t add if number is ODD
MOV A, B ; Get the sum
ADD M ; SUM = SUM + data
MOV B, A ; Store result in B register
SKIP: INX H ; increment pointer
DCR C ; Decrement counter
JNZ BACK ; if counter 0 repeat
STA 2210H ; store sum
HLT ; Terminate program execution
9
------------------------------------------------------------------ 191 of book
=================================================
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
10
JMP END ; Store 00 at 2200H and 2201H
LAST: SHLD 2200H ; Store memory address
END: HLT ; Stop
11
SUB M ; Subtract second operand
INX H ; HL points 2002H
MOV M,A ; Store result at 2002H
HLT ; Terminate program execution
12
------------------------------------------------------------------ 199 of book
=================================================
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
13
DCR C ; Decrement counter
JNZ BACK ; If counter # 0 repeat
HLT ; Stop execution
14
------------------------------------------------------------------ 131 of book
=================================================
LHLD 2000H ; Get first 16-bit number
XCHG ; Save first 16-bit number in DE
LHLD 2002H ; Get second 16-bit number in HL
DAD D ; Add DE and HE
SHLD 2004H ; Store 16-bit result in memory locations 2004H and 2005H.
HLT ; Terminate program execution
------------------------------------------------------------------
=================================================
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
15
------------------------------------------------------------------ 79 of book
=================================================
MOV A, L ; Get lower 2 digits of no. 1
ADD E ; Add two lower digits
DAA ; Adjust result to valid BCD
STA 2300H ; Store partial result
MOV A, H ; Get most significant 2 digits of no. 2
ADC D ; Add two most significant digits
DAA ; Adjust result to valid BCD
STA 2301H ; Store partial result
HLT ; Terminate program execution
------------------------------------------------------------------ 84 of book
=================================================
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 ; Terminate program execution
------------------------------------------------------------------ 84 of book
=================================================
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
16
------------------------------------------------------------------ 87 of book
=================================================
MVI C, 0AH ; Initialize counter
LXI H, 2200H ; Initialize source memory pointer
LXI D, 2300H ; 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
INX D ; Increment destination memory pointer
DCR C ; Decrement counter
JNZ BACK ; If counter 0 repeat
HLT ; Terminate program execution
------------------------------------------------------------------ 88 of book
=================================================
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
------------------------------------------------------------------ 89 of book
=================================================
LHLD 2200H ; Get the dividend
LDA 2202H
MOV C, A ; Get the divisor
LXI D, 0000H ; Quotient = 0
BACK: MOV A, L
SUB C
MOV L, A ; Save partial result
JNC SKIP ; if CY 1 jump
DCR H ; Subtract borrow of previous subtraction
SKIP: INX D ; Increment quotient
17
MOV A, H
CPI 00 ; Check if dividend
JNZ BACK ; < divisor
MOV A, L ; if no repeat
CMP C
JNC BACK
SHLD 2302H ; Store the remainder
XCHG
SHLD 2300H ; Store the quotien
HLT ; Terminate program execution
18
------------------------------------------------------------------ 108 of book
=================================================
LDA 2200H ; Get the number
CMA ; Complement number
STA 2300H ; Store the result
HLT ; Terminate program execution
------------------------------------------------------------------109 of book
=================================================
LDA 2200 H ; Get the number
CMA ; Complement the number
ADI 01H ; Add one in the number
STA 2300H ; Store the result
HLT ; Terminate program execution
------------------------------------------------------------------ 60 of book
=================================================
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
19
------------------------------------------------------------------ 60 of book
=================================================
LXI H,2000H ; Initialize HL register pair as a pointer
; to memory location 2000H
LXI D,2200 H ; Initialize DE register pair as a pointer
; to memory location 2200H
MOV B,M ; Get the contents of memory location
; 1000H into B register
LDAX D ; Get the contents of memory location
; 2000H 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 2200H.
HLT ; Terminate program execution
20
LXI H, 4090H
DAD B
SHLD 2200H
POP H
POP B
RET
21
MOV A,C
ORA B ; Check if count = 0
JNZ BACK ; If not, repeat
HLT ; Stop program execution
DELAY: MVI D,01
BACK1: DCR D
JNZ BACK1
RET
------------------------------------------------------------------
=================================================
22
MVI B,00H
MVI C,08H
MOV A,D
BACK: RAR
JNC SKIP
INR B
SKIP: DCR C
JNZ BACK
HLT
23
JZ SKIP ; If equal, don’t interchange
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H ; Interchange two numbers
SKIP: DCR C ; Decrement counter 2
JNZ BACK ; If not zero, repeat
DCR B ; Decrement counter 1
JNZ START ; If not zero, repeat
HLT ; Terminate program execution
------------------------------------------------------------------ 73 of book
=================================================
24
MOV A,M ; Get first operand
INX H ; HL points 2001H
ADD M ; Add second operand
INX H ; HL points 2002H
MOV M,A ; store result at 2002H
HLT ; Terminate program execution
25
MOV D, E ; Sumhigh = 0
BACK: MOV A, M ; Get the number
ANI 01H ; Mask Bit1 to Bit7
JZ SKIP ; Do not add if number is even
MOV A, E ; Get the lower byte of sum
ADD M ; Sum = sum + data
MOV E, A ; Store result in E register
JNC SKIP
INR D ; Add carry to MSB of SUM
SKIP: INX H ; Increment pointer
DCR C ; Decrement counter
JNZ BACK ; Check if counter 0 repeat
MOV A, E
STA 2300H ; Store lower byte
MOV A, D
STA 2301H ; Store higher byte
HLT ; Terminate program execution
26
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
END: HLT ; Stop
27
=================================================
LXI H, 2200H ; Initialize memory pointer 1
LXI B, 2300H ; Initialize memory pointer 2
LXI D, 2400H ; Initialize result pointer
BACK: LDAX B ; Get the number from array 2
ADD M ; Add it with number in array 1
STAX D ; Store the addition in array 3
INX H ; Increment pointer1
INX B ; Increment pointer2
INX D ; Increment result pointer
MOV A, L
CPI , 0A ; Check pointer1 for last number
JNZ BACK ; If not, repeat
HLT ; Stop
------------------------------------------------------------------ 74 of book
=================================================
LXI H, 2000H ; HL points 2000H
MOV A,M ; Get first operand
INX H ; HL points 2001H
SUB M ; Subtract second operand
INX H ; HL points 2002H
MOV M,A ; Store result at 2002H
HLT ; Terminate program execution
28
------------------------------------------------------------------ 152 of book
=================================================
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
29
DCR C ; decrement count
JNZ BACK ; If not zero, repeat
HLT ; Stop execution
DELAY: LXI D, 0001
BACK1: DCX D
MOV A,E
ORA D
JNZ BACK1
RET
------------------------------------------------------------------ 75 of book
=================================================
LHLD 2000H ; Get first 16-bit number in HL
XCHG ; Save first 16-bit number in DE
LHLD 2002H ; Get second 16-bit number in HL
MOV A, E ; Get lower byte of the first number
ADD L ; Add lower byte of the second number
MOV L, A ; Store result in L register
MOV A, D ; Get higher byte of the first number
ADC H ; Add higher byte of the second number with carry
MOV H, A ; Store result in H register
SHLD 2004H ; Store 16-bit result in memory locations 2004H and 2005H.
HLT ; Terminate program execution
------------------------------------------------------------------ 75 of book
=================================================
LHLD 2000H ; Get first 16-bit number
XCHG ; Save first 16-bit number in DE
LHLD 2002H ; Get second 16-bit number in HL
DAD D ; Add DE and HE
SHLD 2004H ; Store 16-bit result in memory locations 2004H and 2005H.
HLT ; Terminate program execution
------------------------------------------------------------------ 76 of book
=================================================
LHLD 2000H ; Get first 16-bit number in HL
XCHG ; Save first 16-bit number in DE
LHLD 2002H ; Get second 16-bit number in HL
MOV A,E ; Get lower byte of the first number
SUB L ; Subtract lower byte of the second number
MOV L,A ; Store the result in L register
30
MOV A,D ; Get higher byte of the first number
SBB H ; Subtract higher byte of second number with borrow
MOV H,A
SHLD 2004H ; Store 16-bit result in memory locations 2004H and 2005H.
HLT ; Terminate program execution
------------------------------------------------------------------ 78 of book
=================================================
INR B
INR C
INX B
HLT
------------------------------------------------------------------ 79 of book
=================================================
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
31