Example to explain the microcontroller assembler

MCU Assembly Language Programming

1. Write a program using bit manipulation instructions to implement the logic function: "P1.4 = P1.0 ∨ (P1.1 ∧ P1.2) ∨ P1.3".

MOV C, P1.1

ANL C, P1.2

ORL C, P1.0

ORL C, P1.3

MOV P1.4, C

2. Write a program that jumps to the label LABLE if the contents of the accumulator A meet the following conditions, assuming A holds an unsigned number:

(1) A ≥ 10;

(2) A > 10;

(3) A ≤ 10.

(1)

CJNE A, #10, NEXT

LJMP LABLE

NEXT:

JNC LABLE

(2)

CJNE A, #10, NEXT

LJMP NEXT2

NEXT:

JNC LABLE

NEXT2:

(3)

CJNE A, #10, NEXT

LJMP LABLE

NEXT:

JC LABLE

3. Write a program to check if the value 55H exists in the on-chip RAM from address 30H to 50H. If found, set the 51H location to FFH; otherwise, clear it to 0.

MOV R0, #30H

NEXT:

INC R0

CJNE R0, #51H, NEXT2

MOV 51H, #0FFH

AJMP OVER

NEXT2:

CJNE @R0, #55H, NEXT

MOV 51H, #0

OVER:

4. Write a program to count the number of zeros in the on-chip RAM from address 30H to 50H and store the result in the 51H location.

MOV R0, #30H

MOV 51H, #0

NEXT:

CJNE @R0, #00H, NEXT2

INC 51H

NEXT2:

INC R0

CJNE R0, #51H, NEXT

5. There is a block of data in off-chip RAM starting at SOURCE. The data includes characters and numbers. Transfer the data to the on-chip RAM starting at DIST until the end-of-string character "$" is encountered (including the "$", which has ASCII code 24H).

MOV DPTR, #SOURCE

MOV R0, #DIST

NEXT:

MOVX A, @DPTR

MOV @R0, A

INC DPTR

INC R0

CJNE A, #24H, NEXT

6. The 30H and 31H locations of on-chip RAM store a 16-bit binary number with the high bit first and the low bit last. Write a program to invert the bits and save them back.

CLR C

MOV A, #0

SUBB A, 31H

MOV 31H, A

MOV A, #0

SUBB A, 30H

MOV 30H, A

7. Two 4-byte compressed BCD numbers are stored in the on-chip RAM: one from 30H to 33H, and the other from 40H to 43H. Write a program to add these two BCD numbers and store the result in 30H to 33H.

CLR C

MOV R0, #30H

MOV R1, #40H

MOV R2, #4

NEXT:

MOV A, @R0

ADDC A, @R1

MOV @R0, A

INC R0

INC R1

DJNZ R2, NEXT

8. Write a program to transfer 16 bytes of data stored in off-chip RAM starting at 2000H to the on-chip RAM starting at address 30H.

MOV DPTR, #2000H

MOV R0, #30H

MOV R1, #0

NEXT:

MOVX A, @DPTR

MOV @R0, A

INC DPTR

INC R0

INC R1

CJNE R1, #16H, NEXT

Five And More Digits LED Display

Five And More Digits Led Display,Led Display Red Color,10 Segment Led Display,Yellow Segment Led Display

Wuxi Ark Technology Electronic Co.,Ltd. , https://www.arkledcn.com

This entry was posted in on