This action might not be possible to undo. Are you sure you want to continue?

Arithmetic, Logic and Control Instructions

CMPE 310

Intel Assembly Arithmetic Operations: Addition Subtraction Multiplication Division Comparison Negation Increment Decrement Logic Operations: AND OR XOR NOT shift rotate compare (test)

1

[ARRAY + esi] inc byte [edi] .Used for adding 64 bit nums. xadd ecx. Add-with-carry and Exchange-and-add: Contents of the rightmost 8 bits of the FLAGS register can change (+ Overflow) for arithmetic and logic instructions.Adds registers + Carry flag. 2 .ecx=ecx+ebx. ebx=original ecx. Flags include: Z (result zero) C (carry out) A (half carry out) S (result positive) P (result has even parity) O (overflow occurred) add al. Increment.Adds 1 to any reg/mem except seg adc ecx. ebx .Systems Design & Programming Arithmetic. ebx . Logic and Control Instructions CMPE 310 Arithmetic Operations Addition. .

Jump if equal or below. Logic and Control Instructions CMPE 310 Arithmetic Operations Subtraction. Often followed with a conditional branch: cmp al.eax=eax-ebx .Jump if equal or above.if ecx==eax. 3 .Systems Design & Programming Arithmetic. edx . 10H jae LABEL1 jbe LABEL2 cmpxchg ecx.Subs registers . Decrement and Subtract-with-borrow: sub eax. ebx dec edi sbb ecx. ebx Comparison: Changes only the flag bits. eax=edx else eax=ecx .Carry flag. . .

dx|ax=ax*bx (signed) . Division by zero and overflow generate errors.dx|ax=(dx|ax)/cx 4 . div cl idiv cx . 12H ecx .ah|al=ax/cl. Logic and Control Instructions CMPE 310 Arithmetic Operations Multiplication and Division: imul/idiv: Signed integer multiplication/division. unsigned quotient . mul/div: Unsigned. al always holds the multiplicand (or ax or eax). Overflow occurs when a small number divides a large dividend.edx|eax=eax*ecx C and O bits are cleared if most significant 8 bits of the 16-bit product are zero (result of an 8-bit multiplication is an 8-bit result). Result is placed in ax (or dx and ax or edx or eax).Systems Design & Programming Arithmetic.ax=al*bl (unsigned) .Special. dx. cx=dx*12H (signed only) . remainder in ah . mul imul imul mul bl bx cx. in al.

Commonly used with a MASK to clear bits: XXXX XXXX 0000 1111 0000 XXXX Operand Mask Result and al. Commonly used to control I/O devices. AND: 0 AND anything is 0. cleared and complemented. Logic and Control Instructions CMPE 310 Logic Operations Allow bits to be set.Systems Design & Programming Arithmetic.eax=eax OR 0000000AH . 10 .al=al AND bl OR: 1 OR anything is 1. Commonly used with a MASK to set bits: XXXX XXXX 0000 1111 XXXX 1111 Operand Mask Result 5 or eax. bl . Logic operations always clear the carry and overflow flags.

Sets the Z flag to the complement of the bit being tested: test al.Systems Design & Programming Arithmetic. NOT (logical one's complement) NEG (arithmetic two's complement .ah=ah XOR ch TEST: Operates like the AND but doesn't effect the destination. BT: Test the bit.. Commonly used with a MASK to complement bits: XXXX XXXX 0000 1111 XXXX XXXX Operand Mask Result xor ah.Tests bit 2 in al -.00000100 . 4 jz LABEL .sign of number inverted) not ebx neg TEMP 6 .. BTC: Tests and complements. Logic and Control Instructions CMPE 310 Logic Operations XOR: Truth table: 0110.Jump to LABEL if bit 2 is zero. ch .

ebx. rol si. shl eax.Rotate carry bit from previous rcl in dx. . . 7 Commonly used to operate on numbers wider than 32-bits: . 14 rcr bl. bx. shdl ax.eax shifted right by 12 and filled . cl .low order bit of bx. . 12 .si rotated left by 14 places. 1 .eax is logically shifted left 1 bit pos. . cl shl ax. bx and ax. 14 Rotate: Rotates bits from one end to the other or through the carry flag.Shift ax left 1 binary place. .Systems Design & Programming Arithmetic.12 bits of ebx.Rotate carry bit from previous shl into . Logic and Control Instructions CMPE 310 Logic Operations Shift: Logical shifts insert 0.from the left with the right .Original 48-bit number in dx.esi is arithmetically shifted right Double precision shifts (80386 and up): shdr eax. 1 sar esi. arithmetic right shifts insert sign bit. 1 rcl dx.bl rotated right cl places through carry. . 1 rcl bx.

8 . String Scan Instructions: scasb/w/d compares the al/ax/eax register with a byte block of memory and sets the flags.Systems Design & Programming Arithmetic. eax bsr bl.cl scanned from the right. position of bit is saved in destination register. Logic and Control Instructions CMPE 310 Bit/String Scan Bit Scan Instruction (80386 and up): Scan through an operand searching for a 1 bit. cl . Zero flag is set if a 1 bit is found. .eax scanned from the left. bsl ebx. Often used with repe and repne cmpsb/w/d compares 2 sections of memory data.

Far jump: Four bytes give the offset and two bytes give a new segment address. (PC-relative: constant added to eip).Jump to address given by [ax]. jmp far LABEL . jmp near eax jmp [eax] . bx jmp short NEXT .Jump to address given by LABEL. Logic and Control Instructions CMPE 310 Program Control Instructions Conditional and Unconditional Jumps. Interrupts Unconditional Jumps Short jump: PC-relative using two bytes (+127/-128 bytes). Returns. NEXT: add ax. The segment value refers to a descriptor in protected mode. Calls. Near jump: Within segment (max of +/. .2G).Jump to address given by eax. 9 .short keyword is optional.Systems Design & Programming Arithmetic.

or jump if zero (Z=1) . For unsigned numbers: ja jbe . C. Z.Jump if carry set (C=1) .Jump if != (Z=0) .Jump if above (Z=0 and C=0) .Jump if below or equal (Z=1 or C=1) (S<>O) (S=O) For signed numbers jl .Jump if >= For either signed or unsigned: jne je or jz jc jcxz jecxz .Jump if < jge . Logic and Control Instructions CMPE 310 Flow-of-Control Instructions Conditional Jumps: Test flag bits S.Jump if ecx==0 10 Test cx instead of flags: .Systems Design & Programming Arithmetic. P and O.Jump if ==.Jump if cx==0 .

setg al . Logic and Control Instructions CMPE 310 Flow-of-Control Instructions Conditional Set instructions: Set a byte to either 01H or 00H.Jump if (Z = 1 AND ecx != 0) loopne .Set al=1 if >than (test Z==0 AND S==0) . depending on the outcome of condition under test.Systems Design & Programming Arithmetic. jump to label else fall through.Jump if ecx != 0 loope .else set al to 0 LOOP Instruction: Combination of decrement ecx and jnz conditional jump. Example loop LABEL . Decrement ecx If ecx != 0.Jump if (Z = 0 AND ecx != 0) 11 .

Sign up to vote on this title

UsefulNot useful- IntroX86 Map MediumAndSmall
- hood0298.pdf
- ACE201slides_9
- Www.cs.Virginia.edu ~Evans Cs216 Guides x86
- X86 Assembly Guide
- 14 Assembly 2
- 4_4
- ca-lec4
- Joshua Jed Carpena
- Intel 8086 Microprocessor a.
- Olly Script
- 80x86
- Obfuscation code localization based on CFG generation of malware
- Lec4Ass
- IA32
- Parity Flag
- Data Sheet
- IDAPython-Book.pdf
- CONTROLLER_2
- Doc 2455
- MultiLins GeneralElectric
- Intel 8086
- A4-R4
- Isa
- M25P80
- 07 2 IntermediateCodeGen-Quadruples
- dish positioning controlling using radar and telecommunication system
- Ch03CAO
- Interfacing
- x86 Disassembly Exploring the Relationship Between C,x86 Assembly, And Machine Code
- Lab Lect03 Arith Control

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.