0% found this document useful (0 votes)
25 views

Assignement Controller

The document contains code snippets in assembly language for the 8051 microcontroller that perform addition with carry, count the number of ones in a data word, sort numbers in ascending order, and calculate Fibonacci numbers. It shows how instructions like ADDC, RLC, CJNE, MOV, ADD, and DJNZ are used to implement these basic operations and algorithms in 8051 assembly code.

Uploaded by

Deepak Poonia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Assignement Controller

The document contains code snippets in assembly language for the 8051 microcontroller that perform addition with carry, count the number of ones in a data word, sort numbers in ascending order, and calculate Fibonacci numbers. It shows how instructions like ADDC, RLC, CJNE, MOV, ADD, and DJNZ are used to implement these basic operations and algorithms in 8051 assembly code.

Uploaded by

Deepak Poonia
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

For addition of 16 bit data operands instruction ADDC(add with carry) is used ex

:3CE7H+3B8DH=7874 When first bye is added(E7+8D=74,Cy=1) the carry is propagated to the higher byte,which results in 3C+3B+1=78(all in hex).

No of Ones:
mov dptr,#9000h ;Load dptr with 9000h movx a,@dptr ;move data from external memory location to a mov r0,#0h ;load r0 with 0 mov r1,#8h ;load r1 with 8 clr c ;clear carry bit up:rlc a ;rotate a left through carry jnc next ;if no carry, jump to label next inc r0 ;increment r0 next:djnz r1,up ;decrement r1, and jump to label next, if r10 inc dptr ;increment dptr mov a,r0 ;move data from r0 to a movx @dptr,a ;move data from a to external memory location here:sjmp here end

Accending Order:
Org 000h Temp EQU 40h N Equ 04H

MOV R4.#N-1 Loops:Mov DPTR,#2000H MOV r5,r4 Loop1:MOVX A,@DPTR MOV r1,a INC DPTR MOVX A,@ DPTR MOV TEMP,A MOV A,r1 CJNE A,Temp,Loop2 SJMP LOOP3 Loop2:JC Loop3 MOVX @DPTR,A MOV A,TEMP DEC DPL MOVX @DPTR,A INC DPL Loop 3: DJNZ r5,Loop1 DJNZ r4,Loops End

Fibonacci :
mov r1,#0ah ;Load r1 with immediate data 0ah

mov dptr,#9000h ;load 9000h into dptr register movx a,@dptr ; move data from external memory location to a inc dptr ;increment dptr mov r0,a ;move data from a to r0 movx a,@dptr ; move data from external memory location to a back:mov r2,a ;move data from a to r2 add a,r0 ;add a and r0 inc dptr ;increment dptr movx @dptr,a ;move data from a to external memory location mov r3,a ;move data from a to r3 mov a,r2 ; move data from r2 to a mov r0,a ; move data from a to r0 mov a,r3 ; move data from r3 to a djnz r1,back ;decrement r1, if not 0, jump to label back here:sjmp here end

You might also like