Docsity

Instruction Set Architecture, Exercises of Computer Architecture and Organization

Partial preview of the text

Download Instruction Set Architecture and more Exercises Computer Architecture and Organization in PDF only on Docsity!

CS429: Computer Organization and Architecture

Instruction Set Architecture

Dr. Bill Young

Department of Computer ScienceUniversity of Texas at Austin Last updated: October 2, 2019 at 18:

CS429 Slideset 6: 1

Instruction Set Architecture

Topics of this Slideset

Intro to Assembly language Programmer visible state Y86 Rudiments RISC vs. CISC architectures

CS429 Slideset 6: 2

Instruction Set Architecture

Why Y86?

The Y86 is a “toy” machine that is similar to the x86 but

much

simpler

. It is a gentler introduction to assembly level programming than the x86.

just a few instructions as opposedto hundreds for the x86; fewer addressing modes; simpler system state; absolute addressing. Everything you learn about the Y86 will apply to the x86 with verylittle modification.

But the main reason we’re bothering with the

Y86 is because we’ll be explaining pipelining in that context.

CS429 Slideset 6: 4

Instruction Set Architecture

Language / Machine Semantics

There are various means of giving a

semantics

or meaning to a

programming system.Probably the most sensible for an assembly (or machine) languageis an

operational semantics

, also known as an

interpreter semantics

That is, we explain the semantics of each possible operation in thelanguage by explaining the effect that execution of the operationhas on the

machine state

CS429 Slideset 6: 5

Instruction Set Architecture

Y86 Processor State

%rax%rcx%rdx%rbx

%rsp%rbp%rsi%rdi

%r8%r9%r10%r

%r12%r13%r

ZF SF OF

ProgramRegisters

Memory

Conditioncodes PC^

Stat

Program registers: almost the same as x86-64, each 64-bits Condition flags: 1-bit flags set by arithmetic and logicaloperations. OF: Overflow, ZF: Zero, SF: Negative Program counter: indicates address of instruction Memory

Byte-addressable storage array Words stored in little-endian byte order Status code: (status can be AOK, HLT, INS, ADR) toindicate state of program execution.

CS429 Slideset 6: 7

Instruction Set Architecture

Y86 Instructions

We’re actually describing two languages: the assembly languageand the machine language.

There is nearly a 1-1 correspondence

between them. Machine Language Instructions

1-10 bytes of information read from memory

Can determine instruction length from first byte Not as many instruction types and simpler encoding thanx86- Each instruction accesses and modifies some part(s) of theprogram state.

CS429 Slideset 6: 8

Instruction Set Architecture

Example from C to Assembly

Suppose we have the following simple C program in file

code.c

int

sumInts (

long

int

n )

{

/*^

Add

the

integers

from

1.. n.

*/

long

int

i ;

long

int

sum

=

0;

for

(

i

=

1;

i

<=

n ;

i ++

)

{

sum

+=

i ;

}^ return

sum ;

} We used

long int

to force usage of the 64-bit registers. You can

generate assembly using the following command: > gcc -O -S code.c

CS429 Slideset 6: 10

Instruction Set Architecture

x86 Assembly Example

. f i l e

” c o d e. c ”

. t e x t. g l o b l

s u m I n t s

. t y p e

s u m I n t s ,

@ f u n c t i o n

s u m I n t s : .LFB0 :

. c f i

s t a r t p r o c t e s t q

%r d i ,

%r d i

j l e

. L 4

movq

$0 ,

%r a x

movq

$1 ,

%r d x

. L 3 :

addq

%r d x ,

%r a x

addq

$1 ,

%r d x

cmpq

%r d x ,

%r d i

j g e

. L 3

r e t

. L 4 :

movq

$0 ,

%r a x

r e t. c f i

e n d p r o c

.LFE0 :

. s i z e

s u m I n t s ,

.^ −

s u m I n t s

. i d e n t

”GCC :

( Ubuntu

    1. 4

−2ubuntu1 ˜14. 0 4 )

    1. 4 ”

. s e c t i o n

.note.GNU

−s t a c k , ” ” , @ p r o g b i t s

CS429 Slideset 6: 11

Instruction Set Architecture

Encoding Registers

Each register has an associated 4-bit ID:

%rax

%r

%rcx

%r

%rdx

%r

A

%rbx

%r

B

%rsp

%r

C

%rbp

%r

D

%rsi

%r

E

%rdi

no reg

F

Almost the same encoding as in x86-64.Most of these registers are general purpose;

%rsp

has special

functionality.

CS429 Slideset 6: 13

Instruction Set Architecture

Y86 Instruction Set (2)

cmovXX rA,rB

fn^

rA

rB

Encompasses: rrmovq rA,rB

move from register to register

cmovle rA,rB

move if less or equal

cmovl rA,rB

move if less

cmove rA,rB

move if equal

cmovne rA,rB

move if not equal

cmovge rA,rB

move if greater or equal

cmovg rA,rB

move if greater

CS429 Slideset 6: 14

Instruction Set Architecture

Y86 Instruction Set (4)

jXX Dest

fn^

Dest

Encompasses: jmp Dest

unconditional jump

jle Dest

jump if less or equal

jl Dest

jump if less

je Dest

jump if equal

jne Dest

jump if not equal

jge Dest

jump if greater or equal

jg Dest

jump if greater

CS429 Slideset 6: 16

Instruction Set Architecture

Simple Addressing Modes

Immediate:

value

irmovq

$0xab, %rbx

Register:

Reg[R]

rrmovq

%rcx, %rbx

Normal (R):

Mem[Reg[R]]

Register R specifies memory address. This is often called

indirect

addressing.

mrmovq (%rcx), %rax Displacement D(R):

Mem[Reg[R]+D]

Register R specifies start of memory region. Constant displacement D specifies offset mrmovq 8(%rcb),%rdx

CS429 Slideset 6: 17

Instruction Set Architecture

Conventions

The following are conventions necessary to make programs interact:

How do you pass arguments to a procedure? Where are variables (local, global, static) created? How does a procedure return a value? How do procedures preserve the state/data of the caller? Some of these (e.g., the direction the stack grows) are reflected inspecific machine operations; others are purely conventions.

CS429 Slideset 6: 19

Instruction Set Architecture

Sample Program

Let’s write a fragment of Y86 assembly code. Our program swapsthe 8-byte values starting in memory locations 0x0100 (value A)and 0x0200 (value B).^ start :

xorq

% rax ,

% rax

mrmovq

0 x100 (% rax ) ,

% rbx

mrmovq

0 x200 (% rax ) ,

% rcx

rmmovq

% rcx ,

0 x100 (% rax )

rmmovq

% rbx ,

0 x200 (% rax )

halt Reg.

Use

%rax

%rbx

A

%rcx

B

It’s usually a good idea to have a table likethis to keep track of the use of registers. CS429 Slideset 6: 20

Instruction Set Architecture