Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CS 354 - Machine Organization

Monday, October 31, 2016

Last Time
Operands
Data Movement Instructions
Today
Data Movement Instructions (from Wednesday)
Arithmetic and Logical Operations
Condition Code Registers
Next Time
Read: B&O 3.6
Control

Copyright 2016 Jim Skrentny

CS 354 (F16): L24 - 1

Arithmetic Operations

Load Effective Address


leal S,D

LEAL vs. MOV


struct Point {
int x;
int y;
} points[3];

int y = points[i].y;

mov 4(%ebx,%ecx,8), %edx

int *ptry = &points[i].y;

leal 4(%ebx,%ecx,8), %esi

LEAL Simple Math


leal

-3(%ebx), %eax

subl $3, %ebx


movl %ebx, %eax

 Suppose register %eax holds value x and %ecx holds value y.


What value in terms of x and y is stored in %edx for each instruction below?
a) leal 11(%eax), %edx
b) leal (%eax,%ecx,6), %edx
c) leal 4(%ecx,%ecx,8), %edx
d) leal 7(%eax,%ecx,4), %edx

Copyright 2016 Jim Skrentny

CS 354 (F16): L24 - 2

Arithmetic Operations

Unary Operations
INC
DEC
NEG
NOT

D
D
D
D

Binary Operations
ADD S,D
SUB S,D
IMUL S,D
XOR S,D
OR S,D
AND S,D

Given:
0x100
0x104
0x108

0xFF
0xAB
0x10

%eax
%ecx
%edx

0x100
0x1
0x3

 What is the destination and result for each? (do each independently)
a) incl 8(%eax)
a) addl $16, (%eax, %ecx, 4)
b) subl %edx, 0x108
c) addl %ecx, (%eax)

Shift Operations

arithmetic shift
SAL k,D
SAR k,D

logical shift
SHL k,D
SHR k,D

Copyright 2016 Jim Skrentny

CS 354 (F16): L24 - 3

Condition Codes

Flow Control

Condition Code Registers

CF - carry flag
1000
+ 1000

0000
- 0001

0111
+ 0001

1000
- 0001

0111
+ 0001

1000
+ 1000

ZF - zero flag
SF - sign flag
OF - overflow flag

1000
+ 0001

Setting CC based on t = a + b
CF set if
ZF set if
SF set if
OF set if

(unsigned) t < (unsigned) a


t == 0
t < 0
(a < 0 == b < 0)
&& (t < 0 != a < 0)

Copyright 2016 Jim Skrentny

CS 354 (F16): L24 - 4

You might also like