



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Computer Architecture
d O
i^
ti
and Organization
instruction is a one byte
i^
t^
ti
th t d
thi
instruction that does
nothing
does not change any
registers or status bits.
program it is sometimes useful to be ableprogram, it is sometimes useful to be ableto add a few extra instructions that don’tchange the program.
ti
th
i^
t^
ti
executing the instruction.
register.
subtraction but doesn’t store the resultssubtraction, but doesn t store the results.It just sets the status flags.
status register
int dog=-3, cat=3, bird=5, cow;
asm {
// cow = dog + cat
asm
// cow = dog + cat
bird;
mov
eax,dog
add
eax,cat
sub
eax
bird
Zero
Sign
Carry
Overflow
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
sub
eax,bird
mov
cow,eax
0
1
0
0
cmp
instruction compares two values
d
t^
th
t t
fl
i t l
and sets the status flags appropriately.
cmp
register, operand
location or a registerThe compare instruction subtracts the
operand from the register value, but doesnot save the results.
instruction (sometimes called
branch
causes the flow of execution to go )^
g
to a specified location.
instruction loads the Program
Counter with the specified address.
condition is not met.
compare instruction.
easily implemented by a conditional jump. if (cat ==dog)
cow = goat; else
cow = bull;
MOV
eax,cat
CMP
eax,dog
JNE
noteq
MOV
edx,goat
JMP
after
cow
bull;
noteq: MOV
edx,bull
after:
MOV
cow,edx
that directly implement loops (i.e. for,
y
p
p
while, do)
jumps.
while (what == ever) {
again: mov
eax,what
cmp
eax,ever
j^
dl
// something }
jne
endloop
// something^ jmp
again
endloop:
cow=0,
dog=0,
cat=3;
_asm{
do {
// convert this to assembler
cow++;cow
dog = dog + cat;
} while (dog < 12);
cow=0; dog=0; cat=3; _asm{
mov eax, dog
; put dog in eax
again:
inc cow
; cow++
add eax, cat
; add cat to dog
g
cmp eax, 12
jl
again
; repeat if not
mov dog, eax
; save result to dog
i^
l t
dd
manipulate addresses.
assembler.
links in a data structure or to get anlinks in a data structure or to get anelement from an array.
l^
ti
b
i^
th
d
a memory location by using the LoadEffective Address, lea, instruction.
lea
eax, dog ; eax = addr of dog
indexing, the lea instruction will computeindexing, the lea instruction will computethe correct address lea
eax, dog[esi]
; effective addr
in a register in Intel assembler you put thein a register in Intel assembler, you put theregister in the operand field in [brackets]. //
char
cat[47],
goat;
goat
cat[10];
lea
ebx, cat
ebx
= addr of cat
lea
ebx, cat
ebx
addr of cat
add
ebx,
; add 10 to address
mov
al, [ebx]
; al = cat[10]
mov
goat, al
; save in goat
int
*p;
// p is a pointer
i t
5
//
l^
i t
int
x = 5, y;
// regular integers
p = &x;
// p points to x
y = *p;
// y = x = 5
_asm {
mov
ebx p
b
i t
mov
ebx, p
; ebx = pointer p
mov
eax, [ebx]
; eax = x
mov
y, eax
; put value in y
int aray[2][3];
0,
0,
0,
1,
1,
1,
the address of the start of aray + temp
int aray[2][3], i, j, rat; _asm {
rat = aray[i][j];
mov ebx, i
; ebx = i
imul ebx, 3
; ebx = i*
add ebx, j
; ebx = i*3 + j
mov eax, aray[ebx] ; eax = aray[i][j]mov rat, eax
; store in rat