Download presentation
Presentation is loading. Please wait.
Published byWillie Wightman Modified over 9 years ago
1
MOV Instruction MOV destination, source ; copy source to dest. MOV A,#55H ;load value 55H into reg. A MOV R0,A ;copy contents of A into R0 ;(now A=R0=55H) MOV R1,A ;copy contents of A into R1 ;(now A=R0=R1=55H) MOV R2,A ;copy contents of A into R2 ;(now A=R0=R1=R2=55H) MOV R3,#95H ;load value 95H into R3 ;(now R3=95H) MOV A,R3 ;copy contents of R3 into A ;now A=R3=95H
2
Notes on Programming Value (proceeded with #) can be loaded directly to registers A, B, or R0 – R7 –MOV R5, #0F9H If values 0 to F moved into an 8-bit register, the rest assumed all zeros –MOV A, #5 A too large value causes an error –MOV A, #7F2H
3
ADD Instruction ADD A, source ;ADD the source ; operand ;to the accumulator MOV A, #25H ;load 25H into A MOV R2,#34H ;load 34H into R2 ADD A,R2 ;add R2 to accumulator ;(A = A + R2)
4
ADD Instruction and PSW
7
Structure of Assembly Language ORG 0H ;start (origin) at location 0 MOV R5,#25H ;load 25H into R5 MOV R7,#34H ;load 34H into R7 MOV A,#0 ;load 0 into A ADD A,R5 ;add contents of R5 to A ;now A = A + R5 ADD A,R7 ;add contents of R7 to A ;now A = A + R7 ADD A,#12H ;add to A value 12H ;now A = A + 12H HERE: SJMP HERE ;stay in this loop END ;end of asm source file
8
Data Types & Directives ORG 500H DATA1: DB 28 ;DECIMAL (1C in Hex) DATA2: DB 00110101B ;BINARY (35 in Hex) DATA3: DB 39H ;HEX ORG 510H DATA4: DB “2591” ; ASCII NUMBERS ORG 518H DATA6: DB “My name is Joe” ;ASCII CHARACTERS
9
Access RAM Locations Using Register Names
10
Access RAM Locations Using Addresses
11
Switch Register Banks
12
Pushing onto Stack
13
Popping from Stack
14
Stack & Bank 1 Conflict
16
Arithmetic Instructions and Programs
17
Outlines Range of numbers in 8051 unsigned data Addition & subtraction instructions for unsigned data BCD system of data representation Packed and unpacked BCD data Addition & subtraction on BCD data Range of numbers in 8051 signed data Signed data arithmetic instructions Carry & overflow problems & corrections
18
Addition of Unsigned Numbers ADDA, source; A = A + source
20
Addition of Individual Bytes
21
ADDC & Addition of 16-bit Numbers 1 3CE7 3B8D 7874 +
22
BCD Number System Unpacked BCD: 1 byte Packed BCD: 4 bits
23
Adding BCD Numbers & DA Instruction MOVA,#17H ADDA,#28H MOVA,#47H;A=47H first BCD operand MOVB,#25H;B=25 second BCD operand ADDA,B;hex (binary) addition (A=6CH) DAA;adjust for BCD addition (A=72H) HEXBCD 290010 1001 +18 + 0001 1000 410100 0001AC=1 + 6 + 0110 470100 0111
24
Example
25
Subtraction of Unsigned Numbers SUBBA, source; A = A – source – CY SUBB when CY = 0 –Take 2’s complement of subtraend (source) –Add it to minuend –Invert carry
26
Example (Positive Result)
27
Example (Negative Result)
28
SUBB When CY = 1 For multibyte numbers
29
Multiplication of Unsigned Numbers MULAB; A B, place 16-bit result in B and A MOVA,#25H;load 25H to reg. A MOVB,#65H;load 65H in reg. B MULAB;25H * 65H = E99 where ;B = 0EH and A = 99H Table 6-1:Unsigned Multiplication Summary (MUL AB) MultiplicationOperand 1Operand 2Result byte byteABA=low byte, B=high byte
30
Division of Unsigned Numbers DIVAB; divide A by B MOVA,#95H;load 95 into A MOVB,#10H;load 10 into B DIVAB;now A = 09 (quotient) and ;B = 05 (remainder) Table 6-2:Unsigned Division Summary (DIV AB) DivisionNumeratorDenominatorQuotientRemainder byte / byteABAB
31
Example ( 1 of 2 )
32
Example ( 2 of 2 )
33
Signed 8-bit Operands Convert to 2’s complement –Write magnitude of number in 8-bit binary (no sign) –Invert each bit –Add 1 to it
34
Example
37
Byte-sized Signed Numbers Ranges DecimalBinaryHex -1281000 000080 -1271000 000181 -1261000 001082 ….………….. -21111 1110FE -11111 1111FF 00000 000000 +10000 000101 +20000 001002 ……………... +1270111 11117F
38
Overflow in Signed Number Operations
39
When Is the OV Flag Set? Either: there is a carry from D6 to D7 but no carry out of D7 (CY = 0) Or: there is a carry from D7 out (CY = 1) but no carry from D6 to D7
40
Example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.