0 ratings0% found this document useful (0 votes) 74 views19 pagesAssembly 3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
MIPS Memery - — Data Segment
There ave three main types of memory
1s static
2. stack Dynamic
3, Heap Dynamic
Stoic memory isthe simplest. aciit is defined when
the program is assemble and allocated when the
Program. begins execution.
Dynamic memory is allcctted while the program is
running and accessed by addvess offsets, This makes
dynamic memory more difficule to access
programe’ but much more useful.
inva
Flat memory model
“amoFlat memory medel
— ie ex He EE
MIMO
——_— - ——0« 4404 000C
[Keema dota-
sacle ~ Pynomic
alloc hen
vsee Ake
| OM Growp own
A Growr ay i :
duyromic allocstien __. Ox 1904 9000 -
r ded.a. .
a pn oo Psat.
- Paco’ text
raed cre)
De OX BOHO 0000 —-
| oases
D¥ 0060 0000Flat memory model
° ox rete fftt
allocation '
uses lhe
N Grove oo
ea tho gles oid
ico nowi¢ allocation
Ox 1904 nao
E stotic dele ir
C fined — ize)
OX VOOT doo:
be © Prtbegeom: dex i 5
Ctived ~ size)
_ Peerued [T
9% 0000 O000
OX BOO . o000+ Memory consists of one byte ctored after another and,
all bytes are equal
+ The MEPS programmer ceec a memery where the bytes are
Stored as one bid array and the infex te the orray) being
dhe byle addrecs.
+ The memory it addraccible to each by and,dees called
byte addveas.
soThe bite in MPa are organized 195
> argroup af single byte.
> a group of tue bytes ¢ half word ,
> a group of fow bytes ft word
a group of eight bytes + deubles word
These groupe are not random in memory
+ Al) groups starts at 0¥0000; COO0’ and. then
occur at regular intervals
Single byte hal? word
(0x 0000 0000 11 Ox C000 ecco
1 Ox 0000 o001 210% o0ce ce02
21 0x 0000 coo
a
Oxccce coo4
word double word
11 Ox 0000 coco \ Ox 0000 coe
0x 0000 0004
24 Ox 0000 coos
31 Ox0000 coos 3.Ox 0000 0016
Where the memory group storts is called a boundary
+ You cannot addrese a group of data exact ot the
boundary for ‘that ime,
J 0% 0000 C00C Ks mA a bomdary im double werd:
( STF fe I sage, adeblennd © 2)
testatic data
+ gkatic data ia the data that t¢ defined when
Ake program is assembled and allocated when the
program atords te run.
+ Due to the fact thet it ie allocated once, the
size and the locaton af the static data is Pixed
end cannot be changed.
static data is defined ucing the «data assembler
directory.
+ A\\ memory allocated in the program a -data
aegment ic static data
+ Stotic data segment of memory
starting at
address Ox 1000 C000 and continuing untill
address 0x 1004 G000.
Ox 10000000 - Ox 10040000
+ When the assembler starts te execute it keeps
track of the next address available in the data
segment.
+ Tritally he value of the next available data
im the data segment is set to 0x1000 acce.
+ As space is allocated in the data aesment the
next available slot ia increased by the amount
of space repuested +
+ Thic allows the assembler to keep track of where
to store the next data item.eo Hehehe
0x 1001 C00
> -dote
a: sword 0% 1234567
0% tot coor
space 14
bt word On reDeaAye | \ '
© 14 the assembler found ‘data directory the address 40
Start placing data ig Ox 1601 COO
+ A word eH bytes of memory. So tre label @ prints
ko a byle allocation af memory at address and extending
Fo Ox 1001 coos
The .epace directory sete a cide 14 tutes
aavling at Ox 1001 200 and: ending at Ox 1001 O11
+ There ie ne label on this part of date segment ubich
wens the programmer must access it) directly through
an address.
+ The next at label b onothes
The’ memory could have been
in the ner available byte
werd of memery alle Hon
placed at Ox 1001 col
0% 1001 C000
0 X1001 c002
2x 1001 0090 +
© x 1001 cons
oy 1001 a0r8
© x for otsee
= Aeessing memory im MIPS ——
FAL memery acess in MIPS ic done through same form
ef a load or store data,
Operetory t@baden erd9
Tt has tuo Pormets.
Areal feamat
+ im this format an address is stored in Pe and an
offset trem hat addyess stored jm the immediote
vive, The value at Re t immedicte is stared inte Re,
Format : dw Ry sTambdiate (Re)
Meaning 2 Ry < memory [ Ry + Immediate ]
B_Pseude operator
Format ; tw Ras Label
Meaning t Ry Memory C Label 3
Tronslation : tw Re + Ox 1001 e000
tw Py, offeet C Re)
This allows dhe addrese of “the lahel to be stored
ie Re and then Ahe Real
\ood operator is
called 40 the lesd value,[Be] operator (store word.)
seal format
Ain ahis format an eddress ia stored in Re and offset
From thet addiess is stored in the immediote value.
“he value of Ry is stored in memory ot Ret immediate
Formal 1 80 Rye immediate
heaning ¢ memory [Re + Immediate J <— Ry
B_Pseuds operator
Format $ Sw Res Label
meaning 1 memory ( Rs t+Immediate | < Label
Frenslatin : lw Ra - Ox 1001 oc00
sw Ras offset CRe)
— Method and accessing memory
There ove 4 method of addressing dala in MEPS.
1. addreasing by label
a direct access
3, Register indirect acres
be Register offset acces
1 Addressing by tabel
Sometimes Ane oldress of
2 Nebel can be debine or
@ voriable ia
ike addess.
Frown ond
When a variable is stored Im dhe data seqment id can
generally be address divectly using a labelsdext
+ global main
sain t
da 4205 prompt
Jal prompting
move $40 + 4ve
#4 load constants arbre into register |
Iw $45.0
lw tte ob
lw base
4 coleulote y
mult $to. $0. $80
mult to. sto, dte
mult ty» #20, ¢te
add 445, for ats
addi 464. S40, 449
FF ctore the result from fea th y
ow RSA ey
A pied the eulpet ols memery
dw fale y
Jal print and
Jal pind Value
tb Exit program
Jal exit,
+ dada
at seed s
bs
sword 2
et sword 2
Yt sword o
mpl: wascliz ‘Enter your Bateser”
Prompd y + asciiz “* Enter asRegister diveet access
Jy register direct access the vabes ore atored directly
In Abe registers and 0 memory is not access at all
+ tent
ta 4a. prompt
Jal prompt tot
more $20. ¢V0
load a@nstants asbsc into reyicter
Lio bee
i dee
Li $tase
H caleulate y
veut
dhe. Fee. tse
al
Pato, 4to + dee
mult 4414 £505 $46 e
add tte, tte, bey
oda t
44s thos bea
H print dhe outout for y
la 4004 recut :
move $21. $y
+ data
prompt: +asciie “Enter your integer
yesult 2 sasciiz Your vecula ja.”a Register indirect access
The register mdéreci accese doce nod contains
register that te
bat contains The “address
ww be used,
tthe
use im the coleulation
fn memory of the value
values “in the
TH Ake -dato segment hes the numbering of
shard at Ox100\0000 and
variable ‘a
address
variables
will be ot that
stent
input an integer
WF lead @nstants
lui Bte . oxtoo1
lui $45. 0 Chto)
oddi deo. ate
Ie Fae. octesd
addi b4o, Ste. §
Ww 44. 0 C tte)
A caleulade result
# Print vesute
+ data
Ox 1001 000
Ox 1001 ccog
a
b
© ex 1001 ooog
a
© * leet coety Register offees
only change
7 load constants
lu fhe , OC44)
Ie dus, & C440)
Ie gts, & Chto)
ethers are came
Addres: sane
0x 1001 oot
Ox 1008 o100
0% 1905 o108
Ox 1008 0100
oy os o10d
© x 100% o10e
Ox tooe lof
Ox 100% o1o4
access
wate
word
werd
double
twerdFr.
conto) strectue in Assembly Language
Tee stuclures = sequences, branches ond loops.
Bequences 3 that allow programs to execute chlements
iw order ane after another.
Branches 1 thar allow programs to jump other
points in the program
Loops : that allow programs to execute a
fragment Cblock) af cede multiple times,
= Simple if —
+ tf (num sod F
Print CNumber ia positive")
stent et greater tena
+ global main yt ans e :
mai 522 iste
iF Gum 20) * c
wee Wwe tes num 9 8 « mum F245 beclean
gewer 894 FEL y Fto. zero 10 ther die, then te
se a then tars’
eke tino
ihe cda
beqe tts endif “fren
la a0. gositiveNumber
Wi tves +
syscall 7
end if t
Wo svete
syacald
Toque Ewch geil tosere
santa
umf stiordero EEE
me
.
22+ 0) a ee
¥ (Ger0d ER (xv,
° +
lead Ae value 2
Ww tox
agt $11, 440, #2400
sls
bia, bto sa rem thous vhemer S42
eae a oe
sa Ma Pas dee
and 441, ber, 442 2? “
vege 441, endoit
(Sw ee wth a
<< fea. dio.e = di
athio mmove oe
c mohi
—~ziht ee) cee
$to. 2
if (Ged BR (ane
©) A&Cxer) )
te
tho. a
fe ror ee
vem 442, gto sn
pete tee teat ye
sii bts) he, ve
od Hl. tis bes
and $480. tty dag
beg? so.
Cane
‘lao canbe women
mitten as \
popes —
siti
43.10
ae rey)igmple iF... else —
Pimoedt
prind Co“ petitive number”
due?
print CF fegative number (+3
wert
fw Btor%
gt Btls fhe» zero
bear. #4), else
di yo.
da $0, positive Mure
ayscally bet tke Benet on,
> b exit level Uke part of
ween the whole code
or branch breaks
Vi #¥oe & _ “
4 ait) anip some lines
La $40. Negative bum iG SP ;
and continue with
eyacall -
specified location
exit t ike ele. exit
Ui aves to
syscall
date
Positive Num: sasciiz “Positive Number
Negative bum ¢ saacl2 “7 wegative Rumber ™
seq Rye Rew he DP RAT REP Pdol elie Ayre
ogt Ry, Rae Ra > ROrRE Prt clte Ayse
sl pasts Pe > Rec Re Ral ele RareFox ha wrod?
Prina © even”)
ele 7
print Codd?)
r
a text
bettors ee
ate 441, #80 tcor div tose
ae on Phi P40
or Br ee) te ie
an beq2 btl. else
la gac. msg!
Vi geo.
syscallaC Cx <0) Ml Gro) F
print (“Marks should ties beteen @ and too")
7
dise i? Cxs=a0)F print Corde avd F
else iP C >= 80) Z print C~Grode BVIT
else C4 Cm
70) ¢
eke 4 Cx>260)
print CO armde o7) F
print CGrde DDE
else Z print C “Grade sf "JF
+ ege > set grater thon equals
age Rd Rs Ry
dy fos
sh $41, pte. dzero
sti $42 5 b4e 5 100
or #4, bar, ate
beqz FI, gradeA
la 400, meg!
Baye 4
syscall
b exit
graded:
syei al, 440, 10
beqa $1, grade
la hao may 2
i avo,
Syscall
b eid
SrodeBes :
Stade B :
Sgei ar, ato, SO
beqz fEI. gradee
Ya a0, msg 2
Pode Ry
then Ret else Ryso
Weave s
agen
b ewe
grade c+
ager $ti. Sto. 30
bee 441, graded
lo fae, mag
Kayes 4
ysel
beni
grote
agei i tie, 60
beqe Ll, else
la dao . man 6
Wty so
syeent)
be omit
else +
1a 4a0+ vag 5
Wo fye st
agacallWi bye, 10 5
syecal)
weg! ¢ “fark Wee between O and
ag at ** awade A”
~ @rade 8”
* owede c”
“ grode 2”
“ a@mde ©”
eter
int Ls prompt C't endeger an integer
while CT rea dz
rina C% you entered
= prompt Center an integer
ta $20. prompt
5 prompt Trt
490, 4¥0
loop — login :
sne 4ti-
beqz
la
move
440. -1
BEL end_toop,
$005 result
fal, bso
3 printant
la fa0., prompt
J promps Sed
reve
b
$805 bve
loop = tegin
100"
er 7) feel!
er 71 to entre
end—loep =
li tye ste
syscall
pret Tot ¢
Woevestt
ayscal