SlideShare a Scribd company logo
1 of 45
1
Digital Systems and Microprocessor Design
(H7068)
Daniel Roggen
d.roggen@sussex.ac.uk
9.3. Assembler
memory access
2
Content
• Memory interface
• Memory read move instructions
• Memory write move instructions
• Mapping between C pointers and assembler
instructions
3
Memory interface
• The educational processor has a memory interface allowing to read
or write data from memory (or do nothing with it).
• Von Neumann architecture: the memory can contain code or data.
• When and how is the memory used?
• During fetch cycles:
– The processor reads from memory two bytes (one byte during fetchh
and one during fetchl cycles). This is the instruction to execute.
• During the execute cycle:
– The memory is unused if the instruction is not a mov to/from memory
– If the instruction is a mov to memory: one byte is written to the
destination address
– If the instruction is a mov from memory: one byte is read from the
source address
4
Memory interface
• The UoS processor is connected to the RAM with the following lines:
– ram_we (1 bit, processor output): indicates to write the data on
ram_datawr to address ram_address at the next rising edge
– ram_address (5 bits, processor output): indicates the RAM address to
which to write and from which to read
– ram_datawr (8 bits, processor output): indicates the byte to write
– ram_datard (8 bits, processor input): the byte at address ram_address
RAMProcessor
ram_we
ram_address
ram_datawr
ram_datard
5
8
8
we
address
data
q
clk
5
Memory
• Remember a memory is akin to a table where data can be stored at
an address
• The memory implemented alongside the UoS processor on the
FPGA has the following characteristic:
– Synchronous write: it writes “data” to “address” when “we=1” at the next
clock rising edge
– Asynchronous read: “q” is the data at “address”; changing the address
gives immediately (after the propagation time) the data at this address
RAM
Address Data
00 ??
01 ??
02 ??
03 ??
04 ??
6
Memory
• On reset the program counter PC=0. Therefore the
program starts at address 0, and the first instruction
executed on reset is at address 0.
RAM
Address Data
00 ??
01 ??
02 ??
03 ??
04 ??
First instruction executed
on reset.
7
Accessing the memory
• In the UoS processor, the memory can only be accessed
by “mov” instruction
• Reminder: mov dst, src
Instructions instruction(15..8) Instruction(7..0)
Move Opcode dd#m sd#m dreg
(rn)
src (i or rm)
mov rn, rm 0 0 0 0 0 0 r r - - - - - - r r
mov rn, i 0 0 0 1 0 0 r r i i i i i i i i
mov rn, [rm] 0 0 0 0 0 1 r r - - - - - - r r
mov rn, [i] 0 0 0 1 0 1 r r i i i i i i i i
mov [rn], rm 0 0 0 0 1 0 r r - - - - - - r r
mov [rn], i 0 0 0 1 1 0 r r i i i i i i i i
IR /
8
Reading data from a memory location
• Move from memory location can be done with immediate or register
address.
• Immediate address: mov ra,[07h]
– Reads the data at address 07h and puts it into register ra
• Register address: mov ra,[rb]
– Reads the data at address rb and puts it into register ra.
– For example, if rb=09, it reads data at address 09 and puts it into ra
Instructions instruction(15..8) Instruction(7..0)
Move Opcode dd#m sd#m dreg
(rn)
src (i or rm)
mov rn, [rm] 0 0 0 0 0 1 r r - - - - - - r r
mov rn, [i] 0 0 0 1 0 1 r r i i i i i i i i
IR /
9
Reading data from a memory location
mov ra,[07h]
• When executing this instruction (exec
cycle):
– Control unit has put address (07) on
“ram_address”
– The memory is asynchronous for reads
and the value F1h is placed on the
memory output (ram_datard)
– Control unit enables a register file write.
It selects register RA for write. It selects
ram_datard as the data to write.
– On the rising edge in the exec cycle, the
value F1 (coming from the RAM) is thus
stored in RA.
Address Data
00 14
01 07
02 ??
03 ??
04 ??
05 ??
06 ??
07 F1
08 ??
09 DE
0A ??
0B ??
0C ??
0D ??
.. ..
mov ra,[07]
F1 is at
address 07
10
Reading data from a memory location
PC Adr Data Instr RA RB RC
RD
0 0 0 0
-> 00 1407 mov ra,[07h]
02 ???? ??
04 ???? ??
06 ??F1 ??
08 ??DE ??
0A ???? ??
11
Reading data from a memory location
PC Adr Data Instr RA RB RC
RD
F1 0 0 0
00 1407 mov ra,[07h]
-> 02 ???? ??
04 ???? ??
06 ??F1 ??
08 ??DE ??
0A ???? ??
12
Reading data from a memory location
mov rb,09
mov ra,[rb]
• When executing the memory mov
instruction (exec cycle):
– Control unit has put address, which is in
register ra (09) on “ram_address”
– The memory is asynchronous for reads
and the value DEh is placed on the
memory output (ram_datard)
– Control unit enables a register file write.
It selects register a for write. It selects
ram_datard as the data to write.
– On the rising edge in the exec cycle, the
value F1 (coming from the RAM) is thus
stored in RA.
Address Data
00 11
01 09
02 04
03 01
04 ??
05 ??
06 ??
07 F1
08 ??
09 DE
0A ??
0B ??
0C ??
0D ??
.. ..
mov rb,09
DE is at
address 09
mov ra,[rb]
13
Reading data from a memory location
PC Adr Data Instr RA RB RC
RD
0 0 0 0
-> 00 1109 mov rb,09 h
02 0401 mov ra,[rb]
04 ???? ??
06 ??F1 ??
08 ??DE ??
0A ???? ??
14
Reading data from a memory location
PC Adr Data Instr RA RB RC
RD
0 09 0 0
00 1109 mov rb,09 h
-> 02 0401 mov ra,[rb]
04 ???? ??
06 ??F1 ??
08 ??DE ??
0A ???? ??
15
Reading data from a memory location
PC Adr Data Instr RA RB RC
RD
DE 09 0 0
00 1109 mov rb,09 h
02 0401 mov ra,[rb]
-> 04 ???? ??
06 ??F1 ??
08 ??DE ??
0A ???? ??
16
Writing data to a memory location
• Move to memory location can be done only with register address.
The source can be a register or immediate.
– This is due to the choice of instruction encoding; with 16 bit instructions
the UoS processor cannot have immediate memory destination and
immediate source! A different encoding would be required.
• Immediate source: mov [ra],07h
– Writes 07h to the address ra.
– For example, if ra=09, then 07h is written to addres 09h.
• Register source: mov [ra],rb
– Writes the data rb to the addres ra.
Instructions instruction(15..8) Instruction(7..0)
Move Opcode dd#m sd#m dreg
(rn)
src (i or rm)
mov [rn], rm 0 0 0 0 1 0 r r - - - - - - r r
mov [rn], i 0 0 0 1 1 0 r r i i i i i i i i
IR /
17
Writing data to a memory location
mov ra,09h
mov [ra],07
• When executing this instruction (exec
cycle):
– Control unit has put address (09) on
“ram_address”
– Control unit has put data (07) on
ram_datawr.
– Control unit has enabled ram write
“ram_we=1”
– The memory is synchronous for writes.
On the rising edge in the exec cycle, the
value 07 is stored to address 09.
Address Data
00 10
01 09
02 18
03 07
04 ??
05 ??
06 ??
07 ??
08 ??
09 ??
0A ??
0B ??
0C ??
0D ??
.. ..
mov ra,09
mov [ra],07
18
Writing data to a memory location
PC Adr Data Instr RA RB RC
RD
0 0 0 0
-> 00 1000 mov ra,09h
02 1807 mov [ra],07
04 ???? ??
06 ???? ??
08 ???? ??
0A ???? ??
19
Writing data to a memory location
PC Adr Data Instr RA RB RC
RD
09 0 0 0
00 1000 mov ra,09h
-> 02 1807 mov [ra],07
04 ????
06 ????
08 ????
0A ????
20
Writing data to a memory location
PC Adr Data Instr RA RB RC
RD
09 0 0 0
00 1000 mov ra,09h
02 1807 mov [ra],07
-> 04 ????
06 ????
08 ??07
0A ????
21
Writing data to a memory location
mov rb,08h
mov ra,FCh
mov [rb],ra
• When executing this instruction (exec
cycle):
– Control unit has put address (08) on
“ram_address”
– Control unit has put data (FC) on
ram_datawr.
– Control unit has enabled ram write
“ram_we=1”
– The memory is synchronous for writes.
On the rising edge in the exec cycle, the
value FC is stored to address 08.
Address Data
00 11
01 08
02 10
03 FC
04 09
05 00
06 ??
07 ??
08 ??
09 ??
0A ??
0B ??
0C ??
0D ??
.. ..
mov rb,08
mov ra,FC
mov [rb],ra
22
Writing data to a memory location
PC Adr Data Instr RA RB RC
RD
0 0 0 0
-> 00 1108 mov rb,08h
02 10FC mov ra,FCh
04 0900 mov [rb],ra
06 ???? ??
08 ???? ??
0A ???? ??
23
Writing data to a memory location
PC Adr Data Instr RA RB RC
RD
0 08 0 0
00 1108 mov rb,08h
-> 02 10FC mov ra,FCh
04 0900 mov [rb],ra
06 ???? ??
08 ???? ??
0A ???? ??
24
Writing data to a memory location
PC Adr Data Instr RA RB RC
RD
FC 08 0 0
00 1108 mov rb,08h
02 10FC mov ra,FCh
-> 04 0900 mov [rb],ra
06 ???? ??
08 ???? ??
0A ???? ??
25
Writing data to a memory location
PC Adr Data Instr RA RB RC
RD
FC 08 0 0
00 1108 mov rb,08h
02 10FC mov ra,FCh
04 0900 mov [rb],ra
-> 06 ???? ??
08 FC?? ??
0A ???? ??
26
ALU operations with memory operands
• In the UoS processor, ALU operations cannot be directly
performed on memory data. Instead:
– Read the operands from memory and put them in registers
– Perform the ALU operation on the registers
– Write the result register to the destination memory
• Example: read data at address 1C and 1D, add them
together, and store the result at address 1C
mov ra,1Ch
mov rb,[ra]
mov rc,[1Dh]
add rb,rc
mov [ra],rb
27
ALU operations with memory operands
• Other processor architectures may have ALU operations
allowing memory operands.
• This is the case with Intel/AMD x86. The following are
some of the available possibilities:
add reg,reg
add reg,[mem]
add [mem],reg
add reg,imm
add [mem],imm
28
Mixing code and data in memory
• Von Neumann: code and
data can be mixed!
• It is up to the programmer
(or the compiler) to know
where to place data and
code in the memory.
• Only constraint: the first
instruction is at address 0
• This program iterates
between 06-10 according
to the value at address 3
Address Data
00 B0
01 06
02 ??
03 05
04 ??
05 ??
06 14
07 03
08 D0
09 00
0A D0
0B FF
0C 34
0D 01
0E 54
0F 00
10 B9
11 08
.. ??
.. ??
xx B0
xx+1 xx
jmp 06h
mov ra,[03h]
out 00h
out FFh
sub ra,1
cmp ra,0h
jne 08h
This is not executed.
It is either garbage, or
data.
jmp xx
29
Memory move and C pointers
• C pointers directly translate to memory move instructions
– C was designed as a language that easily maps to typical
processor architectures
• C has variables and pointers.
– Pointers are also variables; they allow in addition access to
memory with ‘*’.
• Direct analogy to assembler instructions we have seen!
30
C variables and assembler
• char v1;
– v1 contains a value. May map to a register.
• register char v2;
– v2 contains a value. The keyword “register” indicates the compiler we
wish v2 to be in a register.
• The compiler decides where to store a variable: in memory or in
registers. If registers are available then the compiler will use them
for variables, as this leads to more compact code.
• The “register” keyword indicates the compiler we wish to have the
variable in a register, but it is non-binding.
• Variables can be operated on: incremented, decremented, etc.
• Eg:
register char v1,v2,v3;
v1 = 0x23;
v2 = 0x12;
v3 = v1 + v2; v3 is 0x35 here
31
C variables and assembler
• C:
register char v1,v2,v3;
v1 = 0x23;
v2 = 0x12;
v3 = v1 + v2;
• Let’s assume the human/compiler assigns v1,v2,v3 to ra,rb,rc
respectively.
• Equivalent in assembler:
mov ra,23h
mov rb,12h
mov rc,ra
add rc,rb
Indicates we would like the variables in
registers, but it is non binding.
32
C pointers and assembler
• Pointers are variables that contain a value.... the subtlety is that this
value indicates a memory location that can be read from / written to.
• char *v1;
– v1 contains a value. May map to a register.
• register char *v2;
– v2 contains a value. The keyword “register” indicates the compiler we
wish v2 to be in a register.
• v1 and v2: they contain a value, but this value indicates a memory
location we can read from or write to.
• Eg:
register char *v1,*v2,*v3;
v1 = 0x23;
v2 = 0x12;
v3 = v1 + v2; v3 is 0x35 here
No difference until here!
33
C pointers and assembler
• C:
register char *v1,*v2,*v3;
v1 = 0x23;
v2 = 0x12;
v3 = v1 + v2;
• Pointers are variables that can be modified by arithmetic operations,
just like normal variables.
• Let’s assume the compiler assigns v1,v2,v3 to ra,rb,rc respectively.
• Equivalent in assembler:
mov ra,23h
mov rb,12h
mov rc,ra
add rc,rb
At this point, v3 is 0x35
34
C pointers and assembler
• In addition, pointers can be used to read or write
memory locations.
• Writing byte to address v: *v = x;
– Maps to instructions: mov [rn],i or mov [rn],rm
• Reading byte from address v: x = *v;
– Maps to instruction: mov rn,[i] or mov rn,[rm]
35
C pointers and assembler: writing memory
• Example:
register char *v1,*v2;
v1 = 0x0B;
v2 = 0x0D;
*v1 = 0xFE;
*v2 = 0x3F;
• Assembler:
mov ra,0Bh
mov rb,0Dh
mov [ra],FEh
mov [rb],3Fh
Here writing to memory location 0B and 0D
Here writing to memory location 0B and 0D
36
C pointers and assembler: writing memory
PC Adr Data Instr RA RB RC
RD
0 0 0 0
-> 00 100B mov ra,0Bh
02 110D mov rb,0Dh
04 18FE mov [ra],FEh
06 193F mov [rb],3Fh
08 ???? ??
0A ???? ??
0C ???? ??
0E ???? ??
37
C pointers and assembler: writing memory
PC Adr Data Instr RA RB RC
RD
0B 0 0 0
00 100B mov ra,0Bh
-> 02 110D mov rb,0Dh
04 18FE mov [ra],FEh
06 193F mov [rb],3Fh
08 ???? ??
0A ???? ??
0C ???? ??
0E ???? ??
38
C pointers and assembler: writing memory
PC Adr Data Instr RA RB RC
RD
0B 0D 0 0
00 100B mov ra,0Bh
02 110D mov rb,0Dh
-> 04 18FE mov [ra],FEh
06 193F mov [rb],3Fh
08 ???? ??
0A ???? ??
0C ???? ??
0E ???? ??
39
C pointers and assembler: writing memory
PC Adr Data Instr RA RB RC
RD
0B 0D 0 0
00 100B mov ra,0Bh
02 110D mov rb,0Dh
04 18FE mov [ra],FEh
-> 06 193F mov [rb],3Fh
08 ???? ??
0A ??FE ??
0C ???? ??
0E ???? ??
40
C pointers and assembler: writing memory
PC Adr Data Instr RA RB RC
RD
0B 0D 0 0
00 100B mov ra,0Bh
02 110D mov rb,0Dh
04 18FE mov [ra],FEh
06 193F mov [rb],3Fh
-> 08 ???? ??
0A ??FE ??
0C ??3F ??
0E ???? ??
41
C pointers and assembler: reading memory
• Example:
register char *v1;
register char v2;
v1 = 0x0B;
v2 = *v1;
• Assembler:
mov ra,0Bh
mov rb,[ra]
Here reading from memory location 0B
Here reading from memory location 0B
42
C pointers and assembler: reading memory
PC Adr Data Instr RA RB RC
RD
0 0 0 0
-> 00 100B mov ra,0Bh
02 0500 mov rb,[ra]
04 ???? ??
06 ???? ??
08 ???? ??
0A ??DB ??
0C ???? ??
0E ???? ??
43
C pointers and assembler: reading memory
PC Adr Data Instr RA RB RC
RD
0B 0 0 0
00 100B mov ra,0Bh
-> 02 0500 mov rb,[ra]
04 ???? ??
06 ???? ??
08 ???? ??
0A ??DB ??
0C ???? ??
0E ???? ??
44
C pointers and assembler: reading memory
PC Adr Data Instr RA RB RC
RD
0B DB 0 0
00 100B mov ra,0Bh
02 0500 mov rb,[ra]
-> 04 ???? ??
06 ???? ??
08 ???? ??
0A ??DB ??
0C ???? ??
0E ???? ??
45
Summary
• Assembler instruction “mov” allows to read/write data to
memory
• This allows to perform computations on much more data
than there are registers available.
• Memory can contain data or code (Von Neumann
architecture)
• Direct mapping between memory move operations and
C pointers

More Related Content

What's hot

Computer organization basics
Computer organization  basicsComputer organization  basics
Computer organization basicsDeepak John
 
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISA
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISALec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISA
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISAHsien-Hsin Sean Lee, Ph.D.
 
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1Hsien-Hsin Sean Lee, Ph.D.
 
(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memoryNico Ludwig
 
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- MulticoreLec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- MulticoreHsien-Hsin Sean Lee, Ph.D.
 
301378156 design-of-sram-in-verilog
301378156 design-of-sram-in-verilog301378156 design-of-sram-in-verilog
301378156 design-of-sram-in-verilogSrinivas Naidu
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2Motaz Saad
 
Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086Dheeraj Suri
 
Instruction Set Architecture – II
Instruction Set Architecture – IIInstruction Set Architecture – II
Instruction Set Architecture – IIDilum Bandara
 
N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)Selomon birhane
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controllerTech_MX
 
Blackfin Processor Core Architecture Part 2
Blackfin Processor Core Architecture Part 2Blackfin Processor Core Architecture Part 2
Blackfin Processor Core Architecture Part 2Premier Farnell
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3Motaz Saad
 

What's hot (20)

Al2ed chapter2
Al2ed chapter2Al2ed chapter2
Al2ed chapter2
 
Computer organization basics
Computer organization  basicsComputer organization  basics
Computer organization basics
 
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISA
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISALec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISA
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISA
 
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1
 
Emu8086
Emu8086Emu8086
Emu8086
 
DMA
DMADMA
DMA
 
(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory
 
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- MulticoreLec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
 
Register & Memory
Register & MemoryRegister & Memory
Register & Memory
 
Lecture 9 310h-2
Lecture 9 310h-2Lecture 9 310h-2
Lecture 9 310h-2
 
Patt patelch04
Patt patelch04Patt patelch04
Patt patelch04
 
301378156 design-of-sram-in-verilog
301378156 design-of-sram-in-verilog301378156 design-of-sram-in-verilog
301378156 design-of-sram-in-verilog
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2
 
Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086
 
Instruction Set Architecture – II
Instruction Set Architecture – IIInstruction Set Architecture – II
Instruction Set Architecture – II
 
N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)N_Asm Assembly registers (sol)
N_Asm Assembly registers (sol)
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
 
Blackfin Processor Core Architecture Part 2
Blackfin Processor Core Architecture Part 2Blackfin Processor Core Architecture Part 2
Blackfin Processor Core Architecture Part 2
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3
 
Chapter 8
Chapter 8Chapter 8
Chapter 8
 

Similar to W9_3: UoS Educational Processor: Assembler Memory Access

W8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational ProcessorW8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational ProcessorDaniel Roggen
 
embedded system and computer architecure
embedded system and computer architecureembedded system and computer architecure
embedded system and computer architecuremadhulbtech23
 
Unit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptxUnit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptxVanshJain322212
 
ICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptxICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptxSirRafiLectures
 
Arm cortex-m4 programmer model
Arm cortex-m4 programmer modelArm cortex-m4 programmer model
Arm cortex-m4 programmer modelMohammed Gomaa
 
PattPatelCh04.ppt
PattPatelCh04.pptPattPatelCh04.ppt
PattPatelCh04.pptDipakShow2
 
Computer Organization and Architecture.
Computer Organization and Architecture.Computer Organization and Architecture.
Computer Organization and Architecture.CS_GDRCST
 
Introducción a los microprocesadores vi
Introducción a los microprocesadores viIntroducción a los microprocesadores vi
Introducción a los microprocesadores viayreonmx
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits BVBA (freelancer)
 
PPT in register and micro operations in electronic
PPT in register and micro operations in electronicPPT in register and micro operations in electronic
PPT in register and micro operations in electronicaaravjamela
 
Bootloader and MMU (english)
Bootloader and MMU (english)Bootloader and MMU (english)
Bootloader and MMU (english)Sneeker Yeh
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching materialJohn Williams
 
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor board
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor boardLab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor board
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor boardKatrina Little
 
Assembly language progarmming
Assembly language progarmmingAssembly language progarmming
Assembly language progarmmingAzmeyer
 
Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)Pratheesh Pala
 

Similar to W9_3: UoS Educational Processor: Assembler Memory Access (20)

W8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational ProcessorW8_1: Intro to UoS Educational Processor
W8_1: Intro to UoS Educational Processor
 
embedded system and computer architecure
embedded system and computer architecureembedded system and computer architecure
embedded system and computer architecure
 
ram.pdf
ram.pdfram.pdf
ram.pdf
 
Unit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptxUnit-1_Digital Computers, number systemCOA[1].pptx
Unit-1_Digital Computers, number systemCOA[1].pptx
 
ICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptxICT-Lecture_12(VonNeumannArchitecture).pptx
ICT-Lecture_12(VonNeumannArchitecture).pptx
 
Arm cortex-m4 programmer model
Arm cortex-m4 programmer modelArm cortex-m4 programmer model
Arm cortex-m4 programmer model
 
PattPatelCh04.ppt
PattPatelCh04.pptPattPatelCh04.ppt
PattPatelCh04.ppt
 
CPU.ppd
CPU.ppdCPU.ppd
CPU.ppd
 
Computer Organization and Architecture.
Computer Organization and Architecture.Computer Organization and Architecture.
Computer Organization and Architecture.
 
Introducción a los microprocesadores vi
Introducción a los microprocesadores viIntroducción a los microprocesadores vi
Introducción a los microprocesadores vi
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW Security
 
PPT in register and micro operations in electronic
PPT in register and micro operations in electronicPPT in register and micro operations in electronic
PPT in register and micro operations in electronic
 
Bootloader and MMU (english)
Bootloader and MMU (english)Bootloader and MMU (english)
Bootloader and MMU (english)
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor board
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor boardLab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor board
Lab 7 -RAM and ROM, Xilinx, Digelent BASYS experimentor board
 
S emb t4-arch_cpu
S emb t4-arch_cpuS emb t4-arch_cpu
S emb t4-arch_cpu
 
Assembly language progarmming
Assembly language progarmmingAssembly language progarmming
Assembly language progarmming
 
instruction
instruction instruction
instruction
 
Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)
 

More from Daniel Roggen

Embedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour ScienceEmbedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour ScienceDaniel Roggen
 
W9_2: Jumps and loops
W9_2: Jumps and loopsW9_2: Jumps and loops
W9_2: Jumps and loopsDaniel Roggen
 
W8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational ProcessorW8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational ProcessorDaniel Roggen
 
Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?Daniel Roggen
 
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...Daniel Roggen
 
Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)Daniel Roggen
 
Wearable Computing - Part II: Sensors
Wearable Computing - Part II: SensorsWearable Computing - Part II: Sensors
Wearable Computing - Part II: SensorsDaniel Roggen
 
Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?Daniel Roggen
 

More from Daniel Roggen (12)

Embedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour ScienceEmbedded Sensing and Computational Behaviour Science
Embedded Sensing and Computational Behaviour Science
 
W10: Laboratory
W10: LaboratoryW10: Laboratory
W10: Laboratory
 
W10: Interrupts
W10: InterruptsW10: Interrupts
W10: Interrupts
 
W9: Laboratory 2
W9: Laboratory 2W9: Laboratory 2
W9: Laboratory 2
 
W9_2: Jumps and loops
W9_2: Jumps and loopsW9_2: Jumps and loops
W9_2: Jumps and loops
 
W8: Laboratory 1
W8: Laboratory 1W8: Laboratory 1
W8: Laboratory 1
 
W8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational ProcessorW8_2: Inside the UoS Educational Processor
W8_2: Inside the UoS Educational Processor
 
Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?Wearable technologies: what's brewing in the lab?
Wearable technologies: what's brewing in the lab?
 
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
Wearable Computing - Part IV: Ensemble classifiers & Insight into ongoing res...
 
Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)Wearable Computing - Part III: The Activity Recognition Chain (ARC)
Wearable Computing - Part III: The Activity Recognition Chain (ARC)
 
Wearable Computing - Part II: Sensors
Wearable Computing - Part II: SensorsWearable Computing - Part II: Sensors
Wearable Computing - Part II: Sensors
 
Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?Wearable Computing - Part I: What is Wearable Computing?
Wearable Computing - Part I: What is Wearable Computing?
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

W9_3: UoS Educational Processor: Assembler Memory Access

  • 1. 1 Digital Systems and Microprocessor Design (H7068) Daniel Roggen d.roggen@sussex.ac.uk 9.3. Assembler memory access
  • 2. 2 Content • Memory interface • Memory read move instructions • Memory write move instructions • Mapping between C pointers and assembler instructions
  • 3. 3 Memory interface • The educational processor has a memory interface allowing to read or write data from memory (or do nothing with it). • Von Neumann architecture: the memory can contain code or data. • When and how is the memory used? • During fetch cycles: – The processor reads from memory two bytes (one byte during fetchh and one during fetchl cycles). This is the instruction to execute. • During the execute cycle: – The memory is unused if the instruction is not a mov to/from memory – If the instruction is a mov to memory: one byte is written to the destination address – If the instruction is a mov from memory: one byte is read from the source address
  • 4. 4 Memory interface • The UoS processor is connected to the RAM with the following lines: – ram_we (1 bit, processor output): indicates to write the data on ram_datawr to address ram_address at the next rising edge – ram_address (5 bits, processor output): indicates the RAM address to which to write and from which to read – ram_datawr (8 bits, processor output): indicates the byte to write – ram_datard (8 bits, processor input): the byte at address ram_address RAMProcessor ram_we ram_address ram_datawr ram_datard 5 8 8 we address data q clk
  • 5. 5 Memory • Remember a memory is akin to a table where data can be stored at an address • The memory implemented alongside the UoS processor on the FPGA has the following characteristic: – Synchronous write: it writes “data” to “address” when “we=1” at the next clock rising edge – Asynchronous read: “q” is the data at “address”; changing the address gives immediately (after the propagation time) the data at this address RAM Address Data 00 ?? 01 ?? 02 ?? 03 ?? 04 ??
  • 6. 6 Memory • On reset the program counter PC=0. Therefore the program starts at address 0, and the first instruction executed on reset is at address 0. RAM Address Data 00 ?? 01 ?? 02 ?? 03 ?? 04 ?? First instruction executed on reset.
  • 7. 7 Accessing the memory • In the UoS processor, the memory can only be accessed by “mov” instruction • Reminder: mov dst, src Instructions instruction(15..8) Instruction(7..0) Move Opcode dd#m sd#m dreg (rn) src (i or rm) mov rn, rm 0 0 0 0 0 0 r r - - - - - - r r mov rn, i 0 0 0 1 0 0 r r i i i i i i i i mov rn, [rm] 0 0 0 0 0 1 r r - - - - - - r r mov rn, [i] 0 0 0 1 0 1 r r i i i i i i i i mov [rn], rm 0 0 0 0 1 0 r r - - - - - - r r mov [rn], i 0 0 0 1 1 0 r r i i i i i i i i IR /
  • 8. 8 Reading data from a memory location • Move from memory location can be done with immediate or register address. • Immediate address: mov ra,[07h] – Reads the data at address 07h and puts it into register ra • Register address: mov ra,[rb] – Reads the data at address rb and puts it into register ra. – For example, if rb=09, it reads data at address 09 and puts it into ra Instructions instruction(15..8) Instruction(7..0) Move Opcode dd#m sd#m dreg (rn) src (i or rm) mov rn, [rm] 0 0 0 0 0 1 r r - - - - - - r r mov rn, [i] 0 0 0 1 0 1 r r i i i i i i i i IR /
  • 9. 9 Reading data from a memory location mov ra,[07h] • When executing this instruction (exec cycle): – Control unit has put address (07) on “ram_address” – The memory is asynchronous for reads and the value F1h is placed on the memory output (ram_datard) – Control unit enables a register file write. It selects register RA for write. It selects ram_datard as the data to write. – On the rising edge in the exec cycle, the value F1 (coming from the RAM) is thus stored in RA. Address Data 00 14 01 07 02 ?? 03 ?? 04 ?? 05 ?? 06 ?? 07 F1 08 ?? 09 DE 0A ?? 0B ?? 0C ?? 0D ?? .. .. mov ra,[07] F1 is at address 07
  • 10. 10 Reading data from a memory location PC Adr Data Instr RA RB RC RD 0 0 0 0 -> 00 1407 mov ra,[07h] 02 ???? ?? 04 ???? ?? 06 ??F1 ?? 08 ??DE ?? 0A ???? ??
  • 11. 11 Reading data from a memory location PC Adr Data Instr RA RB RC RD F1 0 0 0 00 1407 mov ra,[07h] -> 02 ???? ?? 04 ???? ?? 06 ??F1 ?? 08 ??DE ?? 0A ???? ??
  • 12. 12 Reading data from a memory location mov rb,09 mov ra,[rb] • When executing the memory mov instruction (exec cycle): – Control unit has put address, which is in register ra (09) on “ram_address” – The memory is asynchronous for reads and the value DEh is placed on the memory output (ram_datard) – Control unit enables a register file write. It selects register a for write. It selects ram_datard as the data to write. – On the rising edge in the exec cycle, the value F1 (coming from the RAM) is thus stored in RA. Address Data 00 11 01 09 02 04 03 01 04 ?? 05 ?? 06 ?? 07 F1 08 ?? 09 DE 0A ?? 0B ?? 0C ?? 0D ?? .. .. mov rb,09 DE is at address 09 mov ra,[rb]
  • 13. 13 Reading data from a memory location PC Adr Data Instr RA RB RC RD 0 0 0 0 -> 00 1109 mov rb,09 h 02 0401 mov ra,[rb] 04 ???? ?? 06 ??F1 ?? 08 ??DE ?? 0A ???? ??
  • 14. 14 Reading data from a memory location PC Adr Data Instr RA RB RC RD 0 09 0 0 00 1109 mov rb,09 h -> 02 0401 mov ra,[rb] 04 ???? ?? 06 ??F1 ?? 08 ??DE ?? 0A ???? ??
  • 15. 15 Reading data from a memory location PC Adr Data Instr RA RB RC RD DE 09 0 0 00 1109 mov rb,09 h 02 0401 mov ra,[rb] -> 04 ???? ?? 06 ??F1 ?? 08 ??DE ?? 0A ???? ??
  • 16. 16 Writing data to a memory location • Move to memory location can be done only with register address. The source can be a register or immediate. – This is due to the choice of instruction encoding; with 16 bit instructions the UoS processor cannot have immediate memory destination and immediate source! A different encoding would be required. • Immediate source: mov [ra],07h – Writes 07h to the address ra. – For example, if ra=09, then 07h is written to addres 09h. • Register source: mov [ra],rb – Writes the data rb to the addres ra. Instructions instruction(15..8) Instruction(7..0) Move Opcode dd#m sd#m dreg (rn) src (i or rm) mov [rn], rm 0 0 0 0 1 0 r r - - - - - - r r mov [rn], i 0 0 0 1 1 0 r r i i i i i i i i IR /
  • 17. 17 Writing data to a memory location mov ra,09h mov [ra],07 • When executing this instruction (exec cycle): – Control unit has put address (09) on “ram_address” – Control unit has put data (07) on ram_datawr. – Control unit has enabled ram write “ram_we=1” – The memory is synchronous for writes. On the rising edge in the exec cycle, the value 07 is stored to address 09. Address Data 00 10 01 09 02 18 03 07 04 ?? 05 ?? 06 ?? 07 ?? 08 ?? 09 ?? 0A ?? 0B ?? 0C ?? 0D ?? .. .. mov ra,09 mov [ra],07
  • 18. 18 Writing data to a memory location PC Adr Data Instr RA RB RC RD 0 0 0 0 -> 00 1000 mov ra,09h 02 1807 mov [ra],07 04 ???? ?? 06 ???? ?? 08 ???? ?? 0A ???? ??
  • 19. 19 Writing data to a memory location PC Adr Data Instr RA RB RC RD 09 0 0 0 00 1000 mov ra,09h -> 02 1807 mov [ra],07 04 ???? 06 ???? 08 ???? 0A ????
  • 20. 20 Writing data to a memory location PC Adr Data Instr RA RB RC RD 09 0 0 0 00 1000 mov ra,09h 02 1807 mov [ra],07 -> 04 ???? 06 ???? 08 ??07 0A ????
  • 21. 21 Writing data to a memory location mov rb,08h mov ra,FCh mov [rb],ra • When executing this instruction (exec cycle): – Control unit has put address (08) on “ram_address” – Control unit has put data (FC) on ram_datawr. – Control unit has enabled ram write “ram_we=1” – The memory is synchronous for writes. On the rising edge in the exec cycle, the value FC is stored to address 08. Address Data 00 11 01 08 02 10 03 FC 04 09 05 00 06 ?? 07 ?? 08 ?? 09 ?? 0A ?? 0B ?? 0C ?? 0D ?? .. .. mov rb,08 mov ra,FC mov [rb],ra
  • 22. 22 Writing data to a memory location PC Adr Data Instr RA RB RC RD 0 0 0 0 -> 00 1108 mov rb,08h 02 10FC mov ra,FCh 04 0900 mov [rb],ra 06 ???? ?? 08 ???? ?? 0A ???? ??
  • 23. 23 Writing data to a memory location PC Adr Data Instr RA RB RC RD 0 08 0 0 00 1108 mov rb,08h -> 02 10FC mov ra,FCh 04 0900 mov [rb],ra 06 ???? ?? 08 ???? ?? 0A ???? ??
  • 24. 24 Writing data to a memory location PC Adr Data Instr RA RB RC RD FC 08 0 0 00 1108 mov rb,08h 02 10FC mov ra,FCh -> 04 0900 mov [rb],ra 06 ???? ?? 08 ???? ?? 0A ???? ??
  • 25. 25 Writing data to a memory location PC Adr Data Instr RA RB RC RD FC 08 0 0 00 1108 mov rb,08h 02 10FC mov ra,FCh 04 0900 mov [rb],ra -> 06 ???? ?? 08 FC?? ?? 0A ???? ??
  • 26. 26 ALU operations with memory operands • In the UoS processor, ALU operations cannot be directly performed on memory data. Instead: – Read the operands from memory and put them in registers – Perform the ALU operation on the registers – Write the result register to the destination memory • Example: read data at address 1C and 1D, add them together, and store the result at address 1C mov ra,1Ch mov rb,[ra] mov rc,[1Dh] add rb,rc mov [ra],rb
  • 27. 27 ALU operations with memory operands • Other processor architectures may have ALU operations allowing memory operands. • This is the case with Intel/AMD x86. The following are some of the available possibilities: add reg,reg add reg,[mem] add [mem],reg add reg,imm add [mem],imm
  • 28. 28 Mixing code and data in memory • Von Neumann: code and data can be mixed! • It is up to the programmer (or the compiler) to know where to place data and code in the memory. • Only constraint: the first instruction is at address 0 • This program iterates between 06-10 according to the value at address 3 Address Data 00 B0 01 06 02 ?? 03 05 04 ?? 05 ?? 06 14 07 03 08 D0 09 00 0A D0 0B FF 0C 34 0D 01 0E 54 0F 00 10 B9 11 08 .. ?? .. ?? xx B0 xx+1 xx jmp 06h mov ra,[03h] out 00h out FFh sub ra,1 cmp ra,0h jne 08h This is not executed. It is either garbage, or data. jmp xx
  • 29. 29 Memory move and C pointers • C pointers directly translate to memory move instructions – C was designed as a language that easily maps to typical processor architectures • C has variables and pointers. – Pointers are also variables; they allow in addition access to memory with ‘*’. • Direct analogy to assembler instructions we have seen!
  • 30. 30 C variables and assembler • char v1; – v1 contains a value. May map to a register. • register char v2; – v2 contains a value. The keyword “register” indicates the compiler we wish v2 to be in a register. • The compiler decides where to store a variable: in memory or in registers. If registers are available then the compiler will use them for variables, as this leads to more compact code. • The “register” keyword indicates the compiler we wish to have the variable in a register, but it is non-binding. • Variables can be operated on: incremented, decremented, etc. • Eg: register char v1,v2,v3; v1 = 0x23; v2 = 0x12; v3 = v1 + v2; v3 is 0x35 here
  • 31. 31 C variables and assembler • C: register char v1,v2,v3; v1 = 0x23; v2 = 0x12; v3 = v1 + v2; • Let’s assume the human/compiler assigns v1,v2,v3 to ra,rb,rc respectively. • Equivalent in assembler: mov ra,23h mov rb,12h mov rc,ra add rc,rb Indicates we would like the variables in registers, but it is non binding.
  • 32. 32 C pointers and assembler • Pointers are variables that contain a value.... the subtlety is that this value indicates a memory location that can be read from / written to. • char *v1; – v1 contains a value. May map to a register. • register char *v2; – v2 contains a value. The keyword “register” indicates the compiler we wish v2 to be in a register. • v1 and v2: they contain a value, but this value indicates a memory location we can read from or write to. • Eg: register char *v1,*v2,*v3; v1 = 0x23; v2 = 0x12; v3 = v1 + v2; v3 is 0x35 here No difference until here!
  • 33. 33 C pointers and assembler • C: register char *v1,*v2,*v3; v1 = 0x23; v2 = 0x12; v3 = v1 + v2; • Pointers are variables that can be modified by arithmetic operations, just like normal variables. • Let’s assume the compiler assigns v1,v2,v3 to ra,rb,rc respectively. • Equivalent in assembler: mov ra,23h mov rb,12h mov rc,ra add rc,rb At this point, v3 is 0x35
  • 34. 34 C pointers and assembler • In addition, pointers can be used to read or write memory locations. • Writing byte to address v: *v = x; – Maps to instructions: mov [rn],i or mov [rn],rm • Reading byte from address v: x = *v; – Maps to instruction: mov rn,[i] or mov rn,[rm]
  • 35. 35 C pointers and assembler: writing memory • Example: register char *v1,*v2; v1 = 0x0B; v2 = 0x0D; *v1 = 0xFE; *v2 = 0x3F; • Assembler: mov ra,0Bh mov rb,0Dh mov [ra],FEh mov [rb],3Fh Here writing to memory location 0B and 0D Here writing to memory location 0B and 0D
  • 36. 36 C pointers and assembler: writing memory PC Adr Data Instr RA RB RC RD 0 0 0 0 -> 00 100B mov ra,0Bh 02 110D mov rb,0Dh 04 18FE mov [ra],FEh 06 193F mov [rb],3Fh 08 ???? ?? 0A ???? ?? 0C ???? ?? 0E ???? ??
  • 37. 37 C pointers and assembler: writing memory PC Adr Data Instr RA RB RC RD 0B 0 0 0 00 100B mov ra,0Bh -> 02 110D mov rb,0Dh 04 18FE mov [ra],FEh 06 193F mov [rb],3Fh 08 ???? ?? 0A ???? ?? 0C ???? ?? 0E ???? ??
  • 38. 38 C pointers and assembler: writing memory PC Adr Data Instr RA RB RC RD 0B 0D 0 0 00 100B mov ra,0Bh 02 110D mov rb,0Dh -> 04 18FE mov [ra],FEh 06 193F mov [rb],3Fh 08 ???? ?? 0A ???? ?? 0C ???? ?? 0E ???? ??
  • 39. 39 C pointers and assembler: writing memory PC Adr Data Instr RA RB RC RD 0B 0D 0 0 00 100B mov ra,0Bh 02 110D mov rb,0Dh 04 18FE mov [ra],FEh -> 06 193F mov [rb],3Fh 08 ???? ?? 0A ??FE ?? 0C ???? ?? 0E ???? ??
  • 40. 40 C pointers and assembler: writing memory PC Adr Data Instr RA RB RC RD 0B 0D 0 0 00 100B mov ra,0Bh 02 110D mov rb,0Dh 04 18FE mov [ra],FEh 06 193F mov [rb],3Fh -> 08 ???? ?? 0A ??FE ?? 0C ??3F ?? 0E ???? ??
  • 41. 41 C pointers and assembler: reading memory • Example: register char *v1; register char v2; v1 = 0x0B; v2 = *v1; • Assembler: mov ra,0Bh mov rb,[ra] Here reading from memory location 0B Here reading from memory location 0B
  • 42. 42 C pointers and assembler: reading memory PC Adr Data Instr RA RB RC RD 0 0 0 0 -> 00 100B mov ra,0Bh 02 0500 mov rb,[ra] 04 ???? ?? 06 ???? ?? 08 ???? ?? 0A ??DB ?? 0C ???? ?? 0E ???? ??
  • 43. 43 C pointers and assembler: reading memory PC Adr Data Instr RA RB RC RD 0B 0 0 0 00 100B mov ra,0Bh -> 02 0500 mov rb,[ra] 04 ???? ?? 06 ???? ?? 08 ???? ?? 0A ??DB ?? 0C ???? ?? 0E ???? ??
  • 44. 44 C pointers and assembler: reading memory PC Adr Data Instr RA RB RC RD 0B DB 0 0 00 100B mov ra,0Bh 02 0500 mov rb,[ra] -> 04 ???? ?? 06 ???? ?? 08 ???? ?? 0A ??DB ?? 0C ???? ?? 0E ???? ??
  • 45. 45 Summary • Assembler instruction “mov” allows to read/write data to memory • This allows to perform computations on much more data than there are registers available. • Memory can contain data or code (Von Neumann architecture) • Direct mapping between memory move operations and C pointers