1 / 15

second word - PowerPoint PPT Presentation

n. bits. first word. second word. • • •. i. th word. • • •. last word. Figure 2.5. Memory words. 32 bits. • • •. b. b. b. b. 31. 30. 1. 0. for positive numbers. Sign bit:. b. =. 0. 31. for negative numbers. b. =. 1. 31. (a) A signed integer. 8 bits.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

PowerPoint Slideshow about ' second word' - rose-cherry

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

bits

first word

second word

i

th word

last word

Figure 2.5. Memory words.

b

b

b

b

31

30

1

0

for positive numbers

Sign bit:

b

=

0

31

for negative numbers

b

=

1

31

(a) A signed integer

8 bits

8 bits

8 bits

8 bits

ASCII

ASCII

ASCII

ASCII

character

character

character

character

(b) Four characters

Figure 2.6.Examples of encoded information in a 32-bit word.

Contents

i

Begin execution here

Move

A,R0

3-instruction

i

+ 4

program

B,R0

segment

i

+ 8

Move

R0,C

A

Data for

B

the program

C

Figure 2.8. A program for C ¬ [A] + [B].

NUM1,R0

i

i

+

4

NUM2,R0

i

+

8

NUM3,R0

i

NUM

n

,R0

+

4

n

-

4

i

4

n

+

Move

R0,SUM

SUM

NUM1

NUM2

NUM

n

Figure 2.9. A straight-line program for addingn numbers.

N,R1

Clear

R0

LOOP

"Next" number to R0

Program

loop

Decrement

R1

Branch>0

LOOP

Move

R0,SUM

SUM

N

n

NUM1

NUM2

NUM

n

Figure 2.10. Using a loop to addn numbers.

Main

memory

B

Operand

A

B

Register

Operand

R1

B

B

(a) Through a general-purpose register

(b) Through a memory location

Contents

Move

N,R1

Initialization

Move

#NUM1,R2

Clear

R0

LOOP

(R2),R0

#4,R2

Decrement

R1

LOOP

Branch>0

Move

R0,SUM

Figure 2.12. Use of indirect addressing in the program of Figure 2.10.

R1

1000

1000

20 = offset

1020

Operand

(a) Offset is given as a constant

1000

20

R1

20 = offset

1020

Operand

(b) Offset is in the index register

N

Student ID

LIST

LIST + 4

Test 1

Student 1

LIST + 8

Test 2

LIST + 12

Test 3

LIST + 16

Student ID

Test 1

Student 2

Test 2

Test 3

Figure 2.14. A list of students' marks.

Clear

R1

Clear

R2

Clear

R3

Move

N,R4

4(R0),R1

LOOP

8(R0),R2

A

d

d

12(R0),R3

#16,R0

Decrement

R4

Branch>0

LOOP

Move

R1,SUM1

R2,SUM2

Move

Move

R3,SUM3

Figure 2.15. Indexed addressing used in accessing test scores in the list in Figure 2.14.

N,R1

Initialization

Move

#NUM1,R2

Clear

R0

LOOP

(R2)+,R0

Decrement

R1

Branch>0

LOOP

Move

R0,SUM

Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.

Move

N,R1

104

Move

#NUM1,R2

108

Clear

R0

LOOP

112

(R2),R0

116

#4,R2

120

Decrement

R1

124

Branch>0

LOOP

128

Move

R0,SUM

132

SUM

200

N

204

100

NUM1

208

NUM2

212

NUM

n

604

Figure 2.17. Memory arrangement for the program in Figure 2.12.

or

data

lab

el

Op

eration

information

Assem

bler

directiv

es

SUM

EQU

200

ORIGIN

204

N

D

A

T

A

W

ORD

100

NUM1

RESER

VE

400

ORIGIN

100

Statemen

ts

that

ST

AR

T

MO

VE

N,R1

generate

MO

VE

#NUM1,R2

mac

hine

CLR

R0

instructions

LOOP

(R2),R0

#4,R2

DEC

R1

BGTZ

LOOP

MO

VE

R0,SUM

Assem

bler

directiv

es

RETURN

END

ST

AR

T

Figure 2.18. Assembly language representation for the program in Figure 2.17.

v

e

#LOC,R0

Initialize

p

oin

ter

register

R0

to

p

oin

t

to

the

of

the

first

lo

cation

in

memory

where

the

c

haracters

are

to

b

e

stored.

T

estBit

#3,INST

A

TUS

W

ait

for

a

c

haracter

to

b

e

en

tered

Branc

h=0

in

the

k

eyb

oard

buffer

D

A

T

AIN.

Mo

v

eByte

D

A

T

AIN,(R0)

T

ransfer

the

c

haracter

from

D

A

T

AIN

in

to

the

memory

(this

clears

SIN

to

0).

ECHO

T

estBit

#3,OUTST

A

TUS

W

ait

for

the

displa

y

to

b

ecome

.

Branc

h=0

ECHO

Mo

v

eByte

(R0),D

A

T

A

OUT

Mo

v

e

the

c

haracter

just

to

the

displa

y

buffer

register

(this

clears

SOUT

to

0).

Compare

#CR,(R0)+

Chec

k

if

the

c

haracter

just

is

CR

(carriage

return).

If

it

is

not

CR,

then

Branc

h

branc

h

bac

k

and

another

c

haracter.

0

Also,

incremen

t

the

p

oin

ter

to

store

the

next

c

haracter.

Figure 2.20. A program that reads a line of characters and displays it.