Microprocessor Programming

You might also like

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

1

MICROPROCESSOR PROGRAMMING

1.Statement: Find the l's complement of the number stored at memory location F000H and store the
complemented number at memory location F100H.

C000...LDA F000H : Get the number


C003 CMA : Complement number
C004 STA F300H : Store the result
C007 HLT : Terminate program execution

2. Statement: Find the 2's complement of the number stored at memory location F000H and store the
complemented number at memory location F100H.

C000...LDA F000H : Get the number


C003 CMA : Complement the number
C004 ADI, 01 H : Add one in the number
C006 STA F100H : Store the result
C009 HLT : Terminate program execution

3. Statement: Exchange the contents of memory locations F000H and F100H

C000 LDAF000H : Get the contents of memory location F000H into accumulator
C003 MOV B, A : Save the contents into B register
C004 LDA F100H : Get the contents of memory location F1000Hinto accumulator
C007 STA F000H : Store the contents of accumulator at address F000H
C00A MOV A, B : Get the saved contents back into A register
C00B STA F100H : Store the contents of accumulator at address F100H

4. Statement: Subtract the contents of memory location F001H from the memory location F000H and
place the result in memory location F002H.

C000 LXI H, F000H : HL points F000H


C003 MOV A, M : Get first operand
C004 INX H : HL pointsF001H
C005 SUB M : Subtract second operand
C006 INX H : HL points F002H
C007 MOV M, A : Store result at F002H.
C008 HLT : Terminate program execution
2

5.Statement: Add the contents of memory locations F000H and F001H and place the result in the
memory locations F002Hand F003H.

C000 LXI H, F000H :HL Points F000H


C003 MOV A, M :Get first operand
C004 INX H :HL Points F001H
C005 ADD M :Add second operand
C006 INX H :HL Points F002H
C007 MOV M, A :Store the lower byte of result at F002H
C008 MVIA, 00 :Initialize higher byte result with 00H
C009 ADC A :Add carry in the high byte result
C00A INX H :HL Points F003H
C00B MOV M, A :Store the higher byte of result at F003H
C00C HLT :Terminate program execution

6.Statement: Pack the two unpacked BCD numbers stored in memory locations F200H and F201H and
store result in memory location F300H. Assume the least significant digit is stored at F200H.

C000 LDA F201H : Get the Most significant BCD digit


C003 RLC
C004 RLC
C005 RLC
C006 RLC : Adjust the position of the second digit (09 is changed to 90)
C007 ANI FOH : Make least significant BCD digit zero
C009 MOV C, A : store the partial result
C00A LDA F200H : Get the lower BCD digit
C00D ADD C : Add lower BCD digit
C00E STA F300H : Store the result
C011 HLT : Terminate program execution

Sample problem:
(F200H) = 04
(F201H) = 09
Result = (F300H) = 94

You might also like