1 / 11

JB b,radd Jump relative if addressable bit is set to 1 JNB b,radd

JB b,radd Jump relative if addressable bit is set to 1 JNB b,radd JBC b,radd Jump relative if addressable bit is set, and clear the addressable bit to 0. Eg:. Byte Jumps: jump instructions that tests bytes of data. If the condition that is tested is true , the jump is taken.

madison
Download Presentation

JB b,radd Jump relative if addressable bit is set to 1 JNB b,radd

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JB b,radd Jump relative if addressable bit is set to 1 JNB b,radd JBC b,radd Jump relative if addressable bit is set, and clear the addressable bit to 0. Eg:

  2. Byte Jumps: jump instructions that tests bytes of data. If the condition that is tested is true, the jump is taken. If the condition is false, the instruction after jump is executed. All byte jumps are relative to the program counter. CJNE A,add,radd Compare the contents of the A register with the contents of the direct address;if they are not equal,then jump to the relative address;set the carry flag to 1 if A<contents of direct address. CJNE A,#n,radd Similar to the above instruction CJNE Rr,#n,radd CJNE @Rp,#n,radd DJNZ Rr,radd ;no flags are affectd DJNZ add,radd ;Decrement the direct address by 1 and jump to the relative address if the result is not zero;no flags are affected unless the direct address is the PSW. JZ radd ;Jump to the relative address if A is 0;the flags and A contents are not changed. JNZ radd

  3. Unconditional Jumps: • They do not test any bit or byte to determine whether the jump should be taken. • All jump ranges are found in this group of jumps as the jump can be to any location in memory. • JMP @A+DPTR ;Jump to the address formed by adding A to the DPTR;the address can be anywhere in the program memory;A,DPTR and the flags are unchanged. • AJMP sadd ;Jump to absolute short range address sadd;no flags are affected • LJMP ladd ;Jump to absolute long range address ladd;no flags are affected. • SJMP radd ;Jump to relative address radd;no flags affected. • NOP(no operation) ;Do nothing and go to the next instruction;used in a software timing loop;no flags affected.

  4. Eg 1: Multiply 25 by 10 using the technique of repeated addition. MOV A,#0 ;CLEAR ACC MOV R2,#10 ;Multiplier is placed in R2 ADD A,#25 ;Add the multiplicand to the ACC DJNZ R2,AGAIN ;Repeat until R2=0 MOV R5,A ;Save ACC in R5. Result:R5=Fah Eg2:WAP to add first ten natural numbers.(1+2+3+…….+10) MOV A,#0 Guess the comments? MOV R2,#10 MOV R0,#0 Again: INC R0 ADD A,R0 DJNZ R2,Again MOV 46H,A

  5. Calls and Subroutine • The change in the program execution can be generated using software instructions called calls. • Call instructions may be included explicitly in the program as mnemonics or implicitly included using hardware interrupts. • In both cases, the call is used to execute a smaller, stand-alone program, which is termed a routine or, more often, a subroutine. • Subroutines • A subroutine is a program that may be used many times in the execution of a larger program. • Calls and the Stack • With the execution of the Call instruction, the stack area of internal RAM is used to automatically store the address (return address),of the instruction found immediately after the call. • The SP register holds the address of the last space used on the stack.

  6. .It stores the return address above this space,adjusting itself upward as the return address is stored. • The sequence of events is shown in the following diagram. • Fig 8.2 from Ayala

  7. Calls and Returns • Calls use short or long range addressing. • Returns have no addressing mode specified but are always long range. • ACALL sadd Call the subroutine located on the same page as the address of the opcode immediately following the ACALL instruction; push the address of the instruction immediately after the call on the stack. • LCALL ladd Call the subroutine located anywhere in program memory space; push the address of the instruction immediately following the call on the stack • RET Pop 2 bytes from the stack into the program counter.

  8. Eg.1:WAP to toggle all the bits of port1 by sending to it the values 55h and AAh continuously. Put a time delay in between each issuing of data to port 1. org 0h Back: mov a,#55h ;load a with 55h mov P1,a ;send 55h to port1 lcall delay ;time dealy mov a,#0AAh ;load a withAAh mov P1,a ;send AAh to port 1 lcall delay sjmp back ;Delay subroutine org 300h ;put time delay at address 300h delay:mov r5,#offh ;r5=255(ff in hex),the counter Again:djnz r5,again ;stay here until r5 becomes 0 ret ;return to caller(when r5=0) end ;end of asm file

  9. Eg.2:WAP to sort an array stored in the internal RAM using subroutine instructions ;This program arranges elements in ascending order in a given ;array in the internal RAM ;5 elements are stored from location 50h ;r0 and r1 are used as data pointers;r2 and r3 are used as ;counters,to keep track of the no. of comparisons in each pass ;and the no. of pass respectively. ;two consecutive elements are compared. If the I element is ;greater than the II element, then the two elements are ;exchanged. org 0000h num equ 040h mov r3,#04h back1: mov r0,#50h ;store n elements(say n=5) from 50h mov a,r0 ;r0 and r1 are used as pointers mov r1,a

  10. mov a,r3 ;load (n-1) to r3 (no. of passes) mov r2,a ;load r3 to r2(no. of comparison in each pass) back: mov a,@r0 ;compare no. pointed to by r0 with no. ;pointed to by r1 inc r1 mov num,@r1 cjne a,num,loop sjmp next loop: jc next ;if num at r0<no. at r1 continue with ;comparison process //jnc next for descending order acall exchg ;else call the subroutine to exchange the ;two numbers next: inc r0 djnz r2,back ;decrement no. of comparison djnz r3,back1 ;decrement no. of passes

  11. here: sjmp here exchg:mov r4,a mov a,@r1 mov @r0,a mov a,r4 mov @r1,a ret end

More Related