Understanding Instruction Set Architecture: A Deep Dive into SAL - Prof. Chen-Nee Chuah, Study notes of Electrical and Electronics Engineering

An introduction to instruction set architecture (isa) using the simple abstract language (sal) as an example. The motivation for using sal, its programming language requirements, data declarations, directives, conditional execution, and input/output operations. It also includes examples of if-else statements, compound conditionals, and loop constructions.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-tzd
koofers-user-tzd 🇺🇸

5

(1)

9 documents

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Page 1
EEC70,Fall2007
Instructor:Chuah
Instructor: ChenNeeChuah
3125KemperHall
Lecture: M/W/F11am12noon
Office Hours: (M)12:301:30pm,(W)1011am*
TeachingAssistants:VictorYip,Kurtis Kredo
Chapter 2: Simple Abstract Language
VariableDeclaration
ArithmeticOperations
ControlStructures
Communicationwithusers,I/O
Procedures
SampleProgram
Chuah,Fall2007 2
ReviewQuestions
Whatarethebasiccomponentsofacomputer?
Whatisaprogramcounter?
Whatarethe6stepsinvolvedintheinstruction
executionsequence?
Howdoyouimplementbranches?
Howmanyoperandscananassemblylanguage
instruction(orstatement)have?
WhatisatypicalsyntaxofMIPSinstructions?
Whatisinstructionsetarchitecture?
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Understanding Instruction Set Architecture: A Deep Dive into SAL - Prof. Chen-Nee Chuah and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

EEC70, Fall 2007

Instructor: Chuah

Instructor: Chen‐Nee Chuah 3125 Kemper Hall Lecture: M/W/F 11am‐12noon Office Hours: (M) 12:30‐1:30pm, (W) 10 ‐11am ***** Teaching Assistants: Victor Yip, Kurtis Kredo

Chapter 2: Simple Abstract Language

Variable Declaration Arithmetic Operations Control Structures Communication with users, I/O Procedures Sample Program

Chuah, Fall 2007 2

Review Questions

ƒ What are the basic components of a computer? ƒ What is a program counter? ƒ What are the 6 steps involved in the instruction execution sequence? ƒ How do you implement branches? ƒ How many operands can an assembly language instruction (or statement) have? ƒ What is a typical syntax of MIPS instructions? ƒ What is instruction set architecture?

Chuah, Fall 2007 3

Reminder: Translation from HLL to

Machine Code

SAL:SAL: Simple AbstractSimple Abstract LanguageLanguage (Chapter 2)(Chapter 2)

MAL:MAL: MIPS AssemblyMIPS Assembly LanguageLanguage (Chapter 8)(Chapter 8)

TAL:TAL: True AssemblyTrue Assembly LanguageLanguage (Chapter 10)(Chapter 10)

HLL Compiler^

Assembly Language Assembler^

Machine Code

Focus on this class

Chuah, Fall 2007 4

Motivation for SAL

ƒ SAL is an intermediate‐level language, makes the transition from high‐level language to low‐level (machine) language easier to understand ‐ Fairly easy to understand (like HLL) and straightforward to translate into MAL (or TAL) ‐ Specific details of the machine language can be postponed

ƒ Progression of learning (with increasing detail):

HLLHLL^ SALSAL^ MALMAL^ TALTAL Machine CodeMachine Code

Chuah, Fall 2007 7

SAL’s Top‐Level Syntax

ƒ One instruction or data declaration per line

ƒ Instructions have at most two operands and produce one result ‐ Some instructions have a single operand

ƒ Comments are anything on a line that follows “#”. Multiple‐line comments require “#” on each line

Chuah, Fall 2007 8

SAL Data Declarations

ƒ Indicate how much memory space a data item needs

ƒ Allow a name (label) to be assigned to that memory space

ƒ Can declare 3 different data types: integer, real, and character

ƒ Example:

C/Java: C/Java: intint area;area; SAL:SAL: area:area: .word.word

Chuah, Fall 2007 9

Declarations (Continued)

ƒ SAL declaration syntax: variable_name: type initial_value

ƒ types are: .byte, .word, and .float

ƒ Examples: count: .word 0 yes: .byte ‘y’ pi: .float 3.

ƒ Initial values are always defined ‐ default value is 0 for .word and .float ‐ “null” character for .byte

Question: So, how many bits really are there in a byte? word? float?

Chuah, Fall 2007 10

Declarations (Continued)

ƒ Format for initial .float values is: {+,‐} {digits}. {digits} {e,E} {+,‐} {digits}

Examples that are the same value:

1.23456E +12.3456e 0.123456e+ 123456E‐ 3

ƒ One declaration per line

Chuah, Fall 2007 13

MACRO: indicate program has completed, Allowing next program to run

Example

.data avg .word i1: .word 20 i2: .word 13 i3: .word 82 .text _start: add avg, i1, i add avg, avg, i div avg, avg, 3 done

Chuah, Fall 2007 14

SAL SAL C/JavaC/Java

move x,ymove x,y x= y;x= y; add x,y,zadd x,y,z x= y+z;x= y+z; sub x,y,zsub x,y,z x= y-x= y-z;z; mul x,y,zmul x,y,z x= y z;x= y z; div x,y,zdiv x,y,z x= y / z;x= y / z; rem x,y,zrem x,y,z x= y % z;x= y % z;

Arithmetic Operations

ƒ SAL’s arithmetic operations are similar to HLL arithmetic operations, except the number of operands is limited to 2 or 1 ‐ Syntax is different

Chuah, Fall 2007 15

Arithmetic Operations (cont.)

ƒ Operands can be a variable (represented by a label), or a constant. Examples: move count, 0 mul product,mult1,mult add sum,this,that ƒ SAL also includes Boolean operations (and, or, xor, etc.) which we’ll cover later

Chuah, Fall 2007 16

Conditional Execution

ƒ Sometimes an instruction should be executed, sometimes not ƒ In C/Java: if (condition) statement else statement ƒ SAL has conditional branches (“conditional gotos”) General forms: b cond x,y label # if cond (x,y) is true, then branch (goto) label b cond x,0 label # if cond (x,0) is true, then branch (goto) label b label # branch unconditionally to label

Chuah, Fall 2007 19

Compiler Optimization

ƒ Compilers use many interesting methods for producing assembly code that is fast and compact. One optimization, reversing the comparison, can be effective for the if‐then‐else example: bgez count,endif add count,count, endif: # next instruction goes here

ƒ One instruction (unconditional branch) is eliminated

Chuah, Fall 2007 20

IF‐Else

ƒ Example C/Java IF: if (A > 0) B = C + D else B = E + F

Chuah, Fall 2007 21

IF‐Else (cont)

ƒ One SAL implementation: blez A, else add B, C, D b endif else: add B, E, F endif: ƒ Second SAL implementation: bgtz A, if add B, E, F b endif if: add B,C,D endif: ƒ Which is best, or is another best?

Chuah, Fall 2007 22

IF‐Else (cont)

ƒ One SAL implementation: blez A, else add B, C, D b endif else: add B, E, F endif: ƒ Second SAL implementation: bgtz A, if add B, E, F b endif if: add B,C,D endif: ƒ Which is best, or is another best?

A>0 A>

Chuah, Fall 2007 25

IF‐Else (cont)

ƒ One SAL implementation: blez A, else add B, C, D b endif else: add B, E, F endif: ƒ Second SAL implementation: bgtz A, if add B, E, F b endif if: add B,C,D endif: ƒ Which is best, or is another best?

A>0 A>

Chuah, Fall 2007 26

IF‐Else (cont)

ƒ One SAL implementation: blez A, else add B, C, D b endif else: add B, E, F endif: ƒ Second SAL implementation: bgtz A, if add B, E, F b endif if: add B,C,D endif: ƒ Which is best, or is another best?

A>0 A>

Chuah, Fall 2007 27

IF‐Else (cont)

ƒ C/Java IF: if (A > 0) B = C + D else B = E + F ƒ Is the same as: B = E + F if (A > 0) B = C + D ƒ SAL: add B, E, F blez A, endif add B,C,D endif: Reduce one line of code!

Chuah, Fall 2007 28

Breakpoint

Chuah, Fall 2007 31

Loop Construction Example: While

ƒ C/Java while (count > 0) { a = a % count; count := count -1; }

ƒ SAL: while: blez count, endwhile rem a,a,count add count,count,- b while endwhile: # next instruction here

Chuah, Fall 2007 32

Loop Construction Example: For

C/Java: for (i=0; i<10; i++) a = a+i;

SAL:

move x,10move x, move i,0move i, for:for:^ bge i,x, endforbge i,x, endfor add a,a,iadd a,a,i add i,i,1add i,i, b forb for endfor:endfor: # next instruction goes here# next instruction goes here

Chuah, Fall 2007 33

SAL’s Input Output Operations

ƒ It is necessary for a program to communicate with the outside world ‐ the user, via keyboard and display ‐ attached peripherals, e.g., printer, scanner, microphone, speaker, etc. ‐ other networked computers ƒ SAL has a very simple set of input/output commands for keyboard and character display I/O ‐ put x # value of x is written to display ‐ get x # x is assigned the value input on keyboard ‐ puts string # writes a character string to display

Chuah, Fall 2007 34

SAL’s I/O Abstraction

my program

Processor

Memory strings reals integers

chars reals integers

  • Abstraction suggests keyboard and display use base 10 integer and real numbers, and alphanumeric characters

Chuah, Fall 2007 37

String Declarations (cont.)

ƒ String label indicates memory location of first character ƒ SAL puts command calls an I/O program, passing it the label address ƒ By agreement, I/O program knows where string ends when it finds a null character, ‘\0’. Thus: prompt:.ascii “Type in your name\0” ƒ For convenience .asciiz directive automatically adds null character at end of string. Thus: prompt:.asciiz “Type in your name”

Chuah, Fall 2007 38

Oddities of get

ƒ get intvar places the first integer variable on the line into intvar, and then discards the rest of the line. Example:

Input: 23 ax 467 ‐ 14 735 1234abc!

SAL code: get int1 # int1 I 23 get int2 # int2 I ‐ 14 get int3 # int3 I 1234

Chuah, Fall 2007 39

Example I/O Program: adds 2 Integers

.data prompt: .asciiz "Enter an integer: " linefeed: .byte '\n' message: .asciiz "The sum is " int1: .word int2: .word sum: .word .text __start: puts prompt # get an integer from user get int put linefeed puts prompt # get a integer from user get int put linefeed add sum, int1, int2 # calculate the sum puts message # print out the sum put sum put linefeed done

Chuah, Fall 2007 40

Example

ƒ What happens when you use .ascii instead of .asciiz and forget to put “\0” at the end of the string declaration