• Nenhum resultado encontrado

32 aula

N/A
N/A
Protected

Academic year: 2021

Share "32 aula"

Copied!
38
0
0

Texto

(1)

Interface Hardware-Software

Aula 3-2

Arithmetic & Logical Instructions

Prof. Dr. Stefan Michael Blawid sblawid@cin.ufpe.br

(2)

IHS - §3 ISA A&L 2

Tópicos

1) Arithmetic Instructions 2) Logical Instructions

(3)

IHS - §3 ISA A&L 3

Status flags

Six flags in the FLAGS register are used to monitor the outcome of the arithmetic, logical, and related operations:

Zero flag (ZF) indicates a zero result

Carry flag (CF) indicates an result that is out of range assuming unsigned numbers

Overflow flag (OF) indicates an result that is out of range assuming signed numbers

Sign flag (SF) indicates a negative sign of the result

Auxiliary flag (AF) indicates an result that has generated a carry out of or a borrow into the low-order four bits

Parity flag (PF) indicates even parity of the lower eight result bits Conditional branch instructions my alter the program flow

(4)

IHS - §3 ISA A&L 4

Tópicos

1) Arithmetic Instructions

(5)

IHS - §3 ISA A&L 5

The

ADD/SUB Instructions

Add without carry; Syntax: add dest, src

Integer addition. The result (dest + src) is assigned to dest Subtract; Syntax: sub dest, src

Integer subtraction. The result (dest - src) is assigned to dest The following combinations are possible:

(6)

IHS - §3 ISA A&L 6

(7)

IHS - §3 ISA A&L 7

(8)

IHS - §3 ISA A&L 8

The

INC/DEC Instructions

Increment by 1; Syntax: inc dest Decrement by 1; Syntax: dec dest The carry flag is not affected

Better than using add/sub because inc/dec are instructions that take up less memory (1 byte = 40H for inc AX instead of 3 bytes = 050100H for add AX 0x0001)

(9)

IHS - §3 ISA A&L 9

(10)

IHS - §3 ISA A&L 10

The

CMP Instruction

Compare two operands; Syntax: cmp dest, src

Compares the two operands specified by performing dest-src Only the flags are updated to reflect the result of the subtract operation

(11)

IHS - §3 ISA A&L 11

(12)

IHS - §3 ISA A&L 12

The

CMPXCHG Instruction

Compare and Exchange; Syntax: cmpxchg dest, src

Compares the value in the AL, AX, or EAX register (depending on the size of the operand) with dest:

If the two values are equal: dest ← src Otherwise: AL, AX or EAX ← src

(13)

IHS - §3 ISA A&L 13

(14)

IHS - §3 ISA A&L 14

More about

CMPXCHG

This instruction was created only starting with the 486 processor Allows atomic comparison and exchange of values by setting the prefix byte accordingly

Example: Consider the following two apparently “identical” code fragments. Is there a difference? Yes, in the first version, an

interrupt might occur between the execution of cmp and mov

(15)

IHS - §3 ISA A&L 15

The

MUL Instruction

Unsigned multiplication; Syntax: mul src

src is a general-purpose register or a memory location

The destination operand is an implied operand located in register AL, AX or EAX (depending on the size of the operand)

(16)

IHS - §3 ISA A&L 16

(17)

IHS - §3 ISA A&L 17

The

IMUL Instruction

Signed multiplication; Syntax:

imul src

imul dest, src

imul dest, src, immediate

The one-operand format works similar as the mul instruction (but for signed multiplication)

The two-operand format performs dest ← dest × src. dest is a 16- or 32-bit general purpose register and src is is an immediate value, a general-purpose register, or a memory location.

The three-operand format performs dest ← src × immediate.

dest is a 16- or 32-bit general purpose register and src is is a general-purpose register, or a memory location.

Obs: For the multiple-operands formats the result of the signed multiplication is of the same length as the input operands

(18)

IHS - §3 ISA A&L 18

(19)

IHS - §3 ISA A&L 19

The

DIV/IDIV Instructions

Unsigned divide; Syntax: div src Signed divide; Syntax: idiv src

src is a general-purpose register or a memory location

-2^7 to 2^7 -1 -2^15 to 2^15 -1

(20)

IHS - §3 ISA A&L 20

(21)

IHS - §3 ISA A&L 21

(22)

IHS - §3 ISA A&L 22

The

NEG Instruction

Negate sign (two’s complement); Syntax: neg dest Replaces the value of dest with its two's complement

dest is a general-purpose register or a memory location Examples:

(23)

IHS - §3 ISA A&L 23

The

CBW/CWD/CWDE/CDQ Instructions

Convert Byte to Word; Syntax: cbw Convert Word to Doubleword: cwde

Both instructions have the same opcode. Which one is executed depends on the operand-size attribute

Doubles the size of the operand in register AL (AX) by sign extension and stores the result in registers AX (EAX)

Convert Word to Doubleword: cwd

Convert Doubleword to Quadword: cdq

Both instructions have the same opcode. Which one is executed depends on the operand-size attribute.

Doubles the size of the operand in register AX (EAX) by sign extension and stores the result in registers DX:AX (EDX:EAX) Useful for preparing operands before a mul or div

(24)

IHS - §3 ISA A&L 24

Tópicos

1) Arithmetic Instructions

(25)

IHS - §3 ISA A&L 25

The

NOT Instruction

Logical bitwise not; Syntax: not dest One’s complement negation

The dest operand can be a register or a memory location Examples:

(26)

IHS - §3 ISA A&L 26

The

AND/OR/XOR Instructions

Logical bitwise and; Syntax: and dest, src Logical bitwise or; Syntax: or dest, src

Logical bitwise exclusive-or; Syntax: xor dest, src

Performs the logical operation on the dest (first) and src (second) operands and stores the result in the dest operand location

(27)

IHS - §3 ISA A&L 27

The

TEST Instruction

Logical compare; Syntax: test dest, src

Computes the bit-wise logical “dest AND src” and sets the SF, ZF, and PF status flags according to the result. The result is discarded. The following combinations are possible:

(28)

IHS - §3 ISA A&L 28

(29)

IHS - §3 ISA A&L 29

Example

Code that tests whether a number is odd or even (assuming a register DX value of 0x0000 or 0x0001 for the Assembly code):

(30)

IHS - §3 ISA A&L 30

The

BSF/BSR Instructions

Bit scan forward; Syntax: bfs dest, src Bit scan reverse; Syntax: bsr dest, src

Scans the bits in src. The ZF flag is set if all bits are 0 and dest is undefined; otherwise, ZF is cleared and the dest register is loaded with the bit index of the first set bit.

bfs starts the scan with the least significant bit and bsr with the

most significant bit.

(31)

IHS - §3 ISA A&L 31

(32)

IHS - §3 ISA A&L 32

The

BT Instructions

Bit test; Syntax: bt scr1, src2

The value of the bit in src1, whose position is indicated by src2, is saved in the carry flag

(33)

IHS - §3 ISA A&L 33

(34)

IHS - §3 ISA A&L 34

The

BTC/BTR/BTS Instructions

Bit test and complement; Syntax: btc src1, scr2 Bit test and reset; Syntax: btr src1, scr2

Bit test and set; Syntax: bts src1, scr2

The value of the bit in src1, whose position is indicated by src2, is saved in the carry flag and then …

… the bit in src1 is complemented (btc)

… the bit in src1 is reset (i.e., cleared) (btr) … the bit in src1 is set (i.e., stores 1) (bts)

src1 is a 16/32 register or memory location; src2 is a 16/32 register or an 8-bit immediate

(35)

IHS - §3 ISA A&L 35

(36)

IHS - §3 ISA A&L 36

The

SETcc Instruction

Set byte on condition; Syntax: setCC dest

Sets dest byte to 1 if the condition CC is met; otherwise, sets to 0

dest must be 8-bit register or memory location

The conditions CC are A, AE, B, BE, C, E, G, GE, L, LE, O, P, S, Z, NA, NAE, NB, NBE, NC, NE, NG, NGE, NL, NLE, NO, NP, NS, NZ, PE, PO

The conditions can specify signed and unsigned comparisons as well as flag values

(37)

IHS - §3 ISA A&L 37

(38)

Referências

Documentos relacionados

Este artigo menciona a mídia social Facebook como exemplo eficiente como propagador da cibercultura e também evidencia o papel do leitor nesse novo paradigma de comunicação

Considerando que a biblioteca desempenha um papel de espaço sociocultural, nasce a ideia deste projeto em criar um espaço social de discussão/reflexão sobre a negritude no

I – estudantes que tenham cursado integralmente o Ensino Fundamental ou Ensino Médio em escolas públicas, em cursos regulares ou no âmbito da modalidade da Educação de Jovens

da CDU, abordando o assunto dos parcómetros, cujo concurso foi anulado pelo Supremo Tribunal Administrativo.--- ---Em seguida, em relação à situação do

Objetivos: Descrever o perfil sociodemográfico e clínico das mulheres com recidiva local do câncer de mama, submetidas à cirurgia conservadora no Hospital Santa Rita de

Nesta senda, podemos com toda a segurança dizer que "a regra é a apreciação da prova segundo as regras da experiência e a livre convicção da entidade

Daniel Welzer-Lang (2005), sociologue français et spécialiste de l’identité masculine, a travaillé sur les femmes violentes dans les couples hétérosexuels. Il en

Por derradeiro, o período depurador, posterior ao qual as faltas disciplinares não mais influirão para a certificação de boa conduta carcerária, tem evidente