week6 - Week 6 Arithmetic, Logic Instructions and Programs...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Week 6 Arithmetic, Logic Instructions and Programs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 ADD Instruction ± Add the source operand to register A and put the result in A. ADD A, source A + source A MOV A,#25H ;load 25H into A ADD A,#34H ;add 34H to A, now A=59H ² The destination operand is always in A. ² The instruction could change CY,AC,OV and P.
Background image of page 2
3 Example 6-1 Show how the flag register is affected by the following instructions. MOV A,#0F5H ;A=F5 hex ADD A,#0BH ;A=F5+0B=00 ± C=1 since there is a carry out from D7. ± P=0 because the number of 1s is 0 (an even number), P is set to 0. ± AC=1 since there is a carry from D3 to D4. F5 + 0B 00
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Example 6-2 Assume that RAM locations 40-44 have the following values. 40=(7D) 41=(EB) 42=(C5) 43=(5B) 44=(30) Write a program to find the sum of the values. At the end of the program, register A should contain the low byte and R7 the high byte. All values are in hex. Solution: MOV R0,#40H ;load pointer MOV R2,#5 ;load counter CLR A ;A=0 MOV R7,A ;clear R7 AGAIN:ADD A,@R0 ;add (R0) JNC NEXT ;jump to carry INC R7 ;keep track of carries NEXT : INC R0 ;increment pointer DJNZ R2,AGAIN ;repeat until R2 is zero
Background image of page 4
5 ADDC ADD with carry ADDC A, source Write a program to add two 16-bit numbers. The numbers are 3CE7H and 3B8DH. Place that sum in R7 and R6; R6 should have the lower byte. Solution: MOV A,#0E7H ;load the low byte now A=E7H ADD A,#8DH ;add the low byte,A=74H and CY=1 MOV R6,A ;save the low byte in R6 MOV A,#3CH ;load the high byte ADDC A,#3BH ;add with the carry MOV R7,A ;save the high byte of the sum
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 INC,DEC ± Supports the following modes ² INC A ² INC RAM_ADDR ² INC Rn ² INC @R0 ² INC @R1 ² DEC A ² DEC RAM_ADDR ² DEC Rn ² DEC @R0 ² DEC @R1 CY is not affected even if value FF is incremented to 00.
Background image of page 6
7 Exercise ± Assume an 8 byte unsigned number x located at 30h-37h ± Assume 8 byte y located at 40h-47h ± Calculate z = x+y and place it at 30-38h
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Solution org 0h mov r2,#08h ; 8 bytes to add mov r0,#30h ; point to first number mov r1,#40h ; point to second number clr c ; clear carry again: mov a,@r0 addc a,@r1 mov @r0,a inc r0 inc r1 djnz r2,again mov @r0,#00h jnc son inc @r0 son: sjmp son end
Background image of page 8
9 Packed/Unpacked BCD ± In (packed) BCD, each decimal digit is represented by a hexadecimal digit which stores the same value. ² In Packed BCD, a byte contains two digits ² 0010 0110b=26H is packed BCD for 26. ± In Unpacked BCD, a byte is used to contain each digit. ² 0000 0101b =05H is unpacked BCD for 5 ² 0000 0010 0000 0110b =02 06H is unpacked BCD for 26 ± Packed BCD is twice as efficient as unpacked BCD in storing data.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Addition of BCD Numbers ± ADD and ADDC are just for hexadecimal! ± To calculate 17+18=35. MOV A,#17H ADD A,#18H A=2FH ² The programmer needs to convert 2FH to 35H ² Can be done by adding 6 to the low digit such that a carry occurs.
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 60

week6 - Week 6 Arithmetic, Logic Instructions and Programs...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online