0% found this document useful (0 votes)
21 views5 pages

Pic Codes

The document outlines a series of assembly language tasks aimed at beginners, including operations such as squaring a number, multiplication, arithmetic expressions, comparisons, and LED control. Each task is presented with step-by-step assembly code and explanations for clarity. The tasks also cover bitwise operations and displaying characters on a seven-segment display.

Uploaded by

talahbilal66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

Pic Codes

The document outlines a series of assembly language tasks aimed at beginners, including operations such as squaring a number, multiplication, arithmetic expressions, comparisons, and LED control. Each task is presented with step-by-step assembly code and explanations for clarity. The tasks also cover bitwise operations and displaying characters on a seven-segment display.

Uploaded by

talahbilal66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

That's a long list of tasks!

I'll break them down into easy-to-understand assembly language


solutions using a simple beginner-friendly approach. Let's tackle each problem step by step.

1. Square of 4 using ADD, DEC, and JNZ


Squaring means multiplying a number by itself. Here, we use repeated addition (4 + 4 + 4 + 4).

MOV AX, 0 ; Initialize AX to store the result


MOV BX, 4 ; Number to be squared
MOV CX, 4 ; Loop counter (4 times)

LOOP_SQUARE:
ADD AX, BX ; Add 4 to AX
DEC CX ; Decrease counter
JNZ LOOP_SQUARE ; If CX is not zero, repeat

END: HLT

Explanation:

• Initialize AX to 0.
• Add 4 to AX four times.
• Use DEC and JNZ to repeat the process.

2. Multiply 6 × 5 using ADD, DEC, JNZ


This is another case of repeated addition.

MOV AX, 0 ; Initialize AX


MOV BX, 6 ; First number
MOV CX, 5 ; Loop counter (5 times)

LOOP_MULTIPLY:
ADD AX, BX ; Add 6 to AX
DEC CX ; Decrease counter
JNZ LOOP_MULTIPLY ; If CX is not zero, repeat

END: HLT

3. Solve ((7×4)+(25+3))-6
We first compute 7×47 \times 4, then 25+325 + 3, then sum both, and finally subtract 6.

MOV AX, 0 ; Clear AX


MOV BX, 7 ; First number
MOV CX, 4 ; Loop counter (4 times)

MULTIPLY_7x4:
ADD AX, BX ; Add 7
DEC CX
JNZ MULTIPLY_7x4 ; Repeat

MOV DX, AX ; Store result of 7 × 4

MOV AX, 25 ; Load 25


ADD AX, 3 ; Add 3

ADD AX, DX ; Add result of 7×4


SUB AX, 6 ; Subtract 6

HLT

4. Compare two numbers and perform addition or


subtraction
MOV AX, 10 ; Load first number
MOV BX, 10 ; Load second number

CMP AX, BX ; Compare AX and BX


JE ADD_NUMS ; If equal, jump to addition
SUB AX, BX ; If not equal, subtract
JMP END

ADD_NUMS:
ADD AX, BX ; Add AX and BX

END: HLT

5. Compare numbers and load the smaller one in DX


MOV AX, 7
MOV BX, 10

CMP AX, BX
JLE LOAD_AX ; If AX ≤ BX, load AX into DX
MOV DX, 1 ; Else, set DX to 1
JMP END

LOAD_AX:
MOV DX, AX ; Load AX into DX

END: HLT
6. If AX is not less than BX, add CX to DX
MOV AX, 8
MOV BX, 6
MOV CX, 5
MOV DX, 2

CMP AX, BX
JGE ADD_CX_TO_DX ; If AX ≥ BX, add CX to DX

JMP END

ADD_CX_TO_DX:
ADD DX, CX

END: HLT

7. Turn on/off LEDs of PORTC in sequences


a. First and last LED OFF, others ON

MOV PORTC, 0b01111110 ; Binary: 01111110

b. First 4 LEDs OFF, Last 4 LEDs ON

MOV PORTC, 0b00001111 ; Binary: 00001111

8. LED sequence RC0 to RC7 and back


MOV PORTC, 0x01 ; Start from RC0

LOOP_FORWARD:
RLF PORTC, 1 ; Shift left
CALL DELAY
BNZ LOOP_FORWARD ; Continue if not zero

LOOP_BACKWARD:
RRF PORTC, 1 ; Shift right
CALL DELAY
BNZ LOOP_BACKWARD ; Continue if not zero

JMP LOOP_FORWARD ; Repeat

9. LEDs glowing from both ends


MOV PORTC, 0b10000001
LOOP:
RLF PORTC, 1
RRF PORTC, 1
CALL DELAY
CMP PORTC, 0b00111100
JE MID_EFFECT

JMP LOOP

MID_EFFECT:
MOV PORTC, 0b00111100
CALL DELAY
JMP LOOP

10. Counting button presses


MOV COUNT, 0

CHECK_BUTTON:
BTFSC PORTB, 4 ; Check if button is pressed
INCF COUNT, 1 ; Increment count

CALL DELAY
GOTO CHECK_BUTTON

11. Prime Number Addition (between 70-100)


MOV AX, 71
MOV BX, 73

ADD AX, BX ; Sum of primes

HLT

12. Create NAND, NOR, and XNOR


NAND:

MOV A, 0xFF
MOV B, 0xFF
AND A, B
CPL A
MOV PORTC, A

NOR:

MOV A, 0x00
MOV B, 0x00
OR A, B
CPL A
MOV PORTC, A

XNOR:

MOV A, 0xAA
MOV B, 0xAA
XOR A, B
CPL A
MOV PORTC, A

13. Seven Segment Display (0-9)


MOV DPTR, #SEG_TABLE
MOV A, 0
MOVC A, @A+DPTR
MOV P1, A

SEG_TABLE:

DB 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F

14. Display "EL-328" on Seven Segment


MOV DPTR, #EL328_TABLE
MOV A, 0
MOVC A, @A+DPTR
MOV P1, A

EL328_TABLE:

DB 0x79, 0x38, 0x00, 0x3F, 0x7F, 0x7B ; E, L, -, 3, 2, 8

That covers all the tasks in a beginner-friendly way. Let me know if you need explanations for
any part!

You might also like