Assembly Language
final
NTNU 組合語言
Ch.07 Integer Arithmetic
7.1 Shift and Rotate Instructions
Bit shifting means to move bits right and left inside an operand. x86 processors provide following instructions, all affecting the Overflow and Carry flags.
instruction |
|
SHL |
Shift left |
SHR |
Shift right |
SAL |
Shift arithmetic left |
SAR |
Shift arithmetic right |
ROL |
Rotate left |
ROR |
Rotate right |
RCL |
Rotate carry left |
RCR |
Rotate carry right |
SHLD |
Double-presicion shift left |
SHRD |
Double-presicion shift right |
7.1.1 Logical Shift and Arithmetic Shifts
- Logical Shift
- fills the newly created bit position with .
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Arithmetic Shift
- fills the newly created bit position with a copy of the number's sign bit
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.1.2 SHL Instruction
- performs a logical left shift on the destination operand
- filling the lowest bit with 0.
- the highest bit is moved to the Carry Flag
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Fast Multiplication
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.1.3 SHR Instruction
- logical right shift
- replace the highest bit with a 0
- the lowest bit is copied to Carry Flag
7.1.4 SAL and SAR Instructions
- SAL (shift arithmetic left) is identical to SHL
- SAR (shift arithmetic right) performs a right arithmetic shift on the destination operand.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.1.5 ROL Instruction
- shifts each bit to the left
- the highest bit is copied into both the Carry flag and into the lowest bit
- No bits are lost
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.1.6 ROR Instruction
- shifts each bit to the right
- The lowest bit is copied into both the Carry flag and into the highest bit
- No bits are lost
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.1.7 RCL and RCR Instruction
- RCL
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- RCR
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.1.8 Signed Overflow
7.1.9 SHLD/SHRD Instructions
- SHLD
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- SHRD
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
7.2 Shift and Rotate Applications
7.3 Multiplication and Division Instructions
7.4 Extended Addition and Subtraction
- Operands are binary values
- Same syntax as ADD, SUB, etc.
- operands must be the same size
ADC Instruction
- adds both a source operand and the contents of the Carry flag to a destination operand.
- example
SBB Instruction
- The SBB (subtract with borrow) instruction subtracts both a source operand and the value of the Carry flag from a destination operand.

7.5 ASCII and Unpacked Decimal Arithmetic
Binary-Coded Decimal (BCD)
- use 4 binary bits to represent each decimal digit
- A number using unpacked BCD representation stores a decimal digit in the lower four bits of each byte
- example : 5,678 stored as the sequence of hexadecimal bytes:

ASCII Decimal
- A number using ASCII Decimal representation stores a single ASCII digit in each byte
- example : 5,678 stored as the sequence of hexadecimal bytes:

AAA Instruction
- ASCII adjust after addition
- adjusts the binary result of an ADD or ADC instruction
- Example add '8' and '2'
AAS Instruction
- ASCII adjust after subtraction
- adjusts the binary result of an SUB or SBB instruction
- Example sub '8' from '9'
AAM Instruction
- ASCII adjust after multiplication
- adjusts the binary result of a MUL instruction
- Example mul '5' and '6'
AAD Instruction
- ASCII adjust before division
- adjusts the unpacked BCD dividend in AX before a division operation
- Example
7.6 Packed Decimal Arithmetic
- Packed BCD
- Packed decimal integers store two decimal digits per byte
- For example, 12,345,678 can be stored as the following sequence of hexadecimal bytes:

DAA Instruction
- decimal adjust after addition
- converts the binary result of an ADD or ADC
- If the lower digit is adjusted, the Auxiliary Carry flag is set.
- If the upper digit is adjusted, the Carry flag is set
- Example: calculate BCD
DAS Instruction
- decinal adjust after subtraction
- converts the binary result of an SUB or SBB
Ch.08 Advanced Procedures
Ch.09 Strings and Arrays
指令 |
描述 |
對ESI跟EDI的影響 |
CLD |
清除方向旗幟 |
遞增 |
STD |
設定方向旗幟 |
遞減 |
9.2 String Primitive Instructions
Instructions |
Description |
MOVSB, MOVSW, MOBSD |
copy data from the memory location pointed to by ESI to the memory location pointed to by EDI |
CMPSB, CMPSW, CMPSD |
compare a memory operand pointed to by ESI to a memory operand pointed to by EDI |
SCASB, SCASW, SCASD |
compare a value in AL/AX/EAX to a byte, word, or doubleword, respectively, addressed by EDI |
STOSB, STOSW, STOSD |
store the contents of AL/AX/EAX, respectively, in memory at the offset pointed to by EDI |
LODSB, LODSW, LODSD |
load a byte or word from memory at ESI into AL/AX/EAX, respectively |
Ch.10 Structures and Macros
Ch.12 Floating-Point Processing and Instruction Encoding
考古題
2019
老大版
S版
吳老大
32位元加16位元版
105
1.
某年