Sei sulla pagina 1di 10

Computer Organization &

Assembly Language
Department of Computer Science

Lecture: 09

1
.ORG Directive
Is used to indicate the beginning of the address
It can be used for both data and code
.ORG 0x300

2
.INCLUDE Directive
Is used to include the contents of a file in the
program
.INCLUDE “M32DEF.INC”

3
Structure of Assembly Program
;AVR assembly language program to add some
data
;store SUM in SRAM location Ox300

.EQU SUM = Ox300 ;SRAM loc $300 for


SUM
.ORG 00 ;start at address 0
LDI Rl6, Ox25 ; Rl6 Ox25
LDI Rl7, $34 ; Rl7 Ox34
LDI Rl8, 0b00110001 ; Rl8 0x31

4
Structure of Assembly Program
ADD Rl6, Rl7 ;add Rl7 to Rl6
ADD Rl6, Rl8 ;add Rl8 to Rl6
LDI Rl7, 11 ;Rl7 = 0x0B
ADD Rl6, Rl7 ;add Rl7 to Rl6
STS SUM, Rl6 ;save the SUM in $300
HERE: JMP HERE ;stay here forever

Operand
Label
Mnemonic Comment 5
Program Space in AVR & PC
The code which is executed by ATmega32 is
stored in 32 KB FLASH ROM
The Code ROM unlike SRAM and Data ROM is
organized as 16 k x 16 memory
◦ 16 K locations each location is 2 bytes
Program Counter holds the address of the Flash
ROM from where the next instruction is fetched
How wide should be the PC?
14 bits = 214 = 16 k locations
What is the default address in PC when processor
is powered up?
$0000 6
Program Code
.EQU SUM = 0x300
.ORG 00
0000 E205 LDI R16, 0x25
0001 E314 LDI R17, $34
0002 E321 LDI R18, 0b00110001
0003 0F01 ADD R16, R17
0004 0F02 ADD R16, R18
0005 E01B LDI R17, 11
0006 0F01 ADD R16, R17
0007 9300 0300 STS SUM, R16
0009 940C 0009 HERE: JMP HERE

7
LDI Instruction Code
LDI is 2 byte instruction
LDI Rd, k
1110 kkkk dddd kkkk
LDI R16, 0x25 1110 0010 0000 0101 E205
LDI R17, $34 1110 0011 0001 0100 E314
LDI R18, 0b001100011110 0011 0010 0001 E321

8
ADD Instruction Code
ADD is 2 byte instruction
ADD Rd, Rr
0000 11rd dddd rrrr
ADD R16, R17 0000 1111 0000 0001 0F01
ADD R16, R18 0000 1111 0000 0010 0F02

9
STS Instruction Code
STS is 4 byte instruction
STS k, Rr
1001 001r rrrr 0000
kkkk kkkk kkkk kkkk
STS SUM R16 1001 0011 0000 0000 9300
0000 0011 0000 0000 0300

10

Potrebbero piacerti anche