No Slide Title

Download Report

Transcript No Slide Title

CPSC 171 Introduction to
Computer Science
Assembly Language and Assemblers
Machine Code
Address
000000
000001
000010
000011
000100
000101
000110
…
Value
1101 000101
No1101
natural000110
language
0000 000101
Difficult to change
0111 000110
Data
stored
in binary
1111
000000
0000 000000
0000 000000
2
Assembly Language
Symbolic Operations
Symbolic Memory Addresses
Has Pseudo-operations for data
generation
3
4
Structure of Assembly Code
Label: op-code symbol address label --comment
5
Example Assembly Code
loop:
done:
x:
y:
.begin
in x
in y
load x
compare y
jumpgt done
out x
jump loop
out y
halt
.data 0
.data 0
.end
6
op-code Symbol
REF: page 248, Fig 6.5
Arithmetic OpCodes
0000 load
0001 store
0010 clear
0011 add
0100 increment
0101 subtract
0110 decrement
I/0 OpCodes
1101 in
1110 out
Logic/Control
OpCodes
0111 compare
1000 jump
1001 jumpgt
1010 jumpeq
1011 jumplt
1100 jumpneq
1111 halt
7
Convert Pseudocode to
Assembly code
1.
2.
3.
4.
5.
6.
7.
8.
9.
Set NegCount to 0
Set I to 1
While I ≤ 5 do lines 4 through 6
Input a number, N
if N < 0 then increment NegCount
Increment I
End of loop
Output NegCount
Stop
8
Assembly Code
loop:
dont_add:
finish:
NegCount:
I:
FIVE:
N:
NEG_ONE:
.begin
load FIVE
compare I
jumpgt finish
in N
load N
compare NEG_ONE
jumplt dont_add
increment NegCount
jump loop
out NegCount
halt
.data 0
.data 1
.data 5
.data 0
.data -1
.end
9
You Try It
Create Assembly Code for the following algorithm:
Get a number X
Get a number Y
If Y > X then
print out Y
Else
print out X
Stop
10