









Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Prepara tus exámenes
Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Prepara tus exámenes con los documentos que comparten otros estudiantes como tú en Docsity
Encuentra los documentos específicos para los exámenes de tu universidad
Estudia con lecciones y exámenes resueltos basados en los programas académicos de las mejores universidades
Responde a preguntas de exámenes reales y pon a prueba tu preparación
Consigue puntos base para descargar
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Comunidad
Pide ayuda a la comunidad y resuelve tus dudas de estudio
Ebooks gratuitos
Descarga nuestras guías gratuitas sobre técnicas de estudio, métodos para controlar la ansiedad y consejos para la tesis preparadas por los tutores de Docsity
Asignatura: Fonaments d'Informàtica, Profesor: , Carrera: Enginyeria Electrònica de Telecomunicació, Universidad: UAB
Tipo: Apuntes
1 / 17
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!










Joan Oliver 2
VonVon NeumannNeumann ArchitectureArchitecture (I)(I)
Joan Oliver 3
Unitat de control
Memòria principal
Unitat d’E/S
Perifèric
Perifèric
Perifèric
VonVon NeumannNeumann ArchitectureArchitecture (II)(II)
Joan Oliver 4
Processor structure: ◦ CPU (Data Path + Control Unit), with a finite state machine control unit
◦ Read/write program memory. During the program running, the l b d
EduP12EduP12 processorprocessor (II)(II)
memory can only be read.
◦ Read/write data memory. The stack starts at the end of the memory, and grows towards the beginning. ◦ Input/output registers. Each peripheral communicates with the CPU using registers. Each input/output register is accessed using a specific address.
EduP12EduP12 CPUCPU
Joan Oliver 8
CPUCPU operation:operation: ADD:ADD: RdRd RdRd ++ RsRs
ADD instruction code: 0000 10sd dddd ssss
Joan Oliver 9
CPUCPU operation:operation: BRMI:BRMI: PCPC PC+1+kPC+1+k
Next instruction is a conditional branch. In fact, stored program corresponds to:
loop: ADD R17, R
BRMI loop
Joan Oliver 10
Arithmetic‐logical instructions ◦ Double register: MOV, ADD, ADC, SUB, SBC, CP, CPC, AND, OR, EOR, TST ◦ Simple register: INC, DEC, COM, NEG, CLR, ASR, LSR, LSL, ROR, ROL, SWAP ◦ Immediate: LDI, ADDI, ANDI, ORI, SUBI, SBCI, CPI, TSTI
EduP12EduP12 InstructionInstruction setset reviewreview
Data transfer instructions ◦ Program memory: Load instructions: LPM, LPM+ ◦ Data memory: Load instructions: LDS, LD, LD+, LD‐, LDD Store instructions: STS, ST, ST+, ST‐, STD Jump instructions ◦ Unconditional: RJMP, RCALL, RET, RETI. ◦ Indirect conditional: IJMP, ICALL.
Joan Oliver 13
◦ Conditional. BRBC, BRBS, BRCC , BRCS, BRSH, BRLO, BRZE, BRNZ, BRNE, BREQ, BRMI, BRPL, BRVC, BRVS, BRIE, BRID. Input/output instructions: IN, OUT Status register instructions: BSET, BCLR, SEI, CLI Other instructions ◦ Stack: POP, PUSH, SAVE, RESTORE. ◦ Do nothing: NOP.
WhatWhat instructions?instructions? WhatWhat dodo theythey do?do? InstructionInstruction setset
Instruction State Code Words Cycles
MOV Rd, Rs AND Rd, Rs ADC Rd, Rs ADD Rd, Rs
Rd Rs Rd RdRs Rd Rd+Rs+C Rd Rd+Rs
Move Logic and Add with carry Add
0000 01sd dddd ssss 0010 00sd dddd ssss 0000 11sd dddd ssss 0000 10sd dddd ssss
ADD Rd, Rs 3 CP Rd, Rs CPC Rd, Rs EOR Rd, Rs OR Rd, Rs SBC Rd, Rs SUB Rd, Rs TST Rd, Rs
Rd Rd+Rs ‐ Rd‐Rs ‐ Rd‐(Rs+C) Rd RdRs Rd RdRs Rd Rd‐(Rs+C) Rd Rd‐Rs ‐ RdRs
Add Compare Compare with carry Logic or‐exclusive Logic or Subtract with carry Subtract Bit to bit test
0000 10sd dddd ssss 0001 10sd dddd ssss 0001 11sd dddd ssss 0010 10sd dddd ssss 0010 01sd dddd ssss 0001 01sd dddd ssss 0001 00sd dddd ssss 0010 11sd dddd ssss
ASR Rd CLR Rd COM Rd DEC Rd
Rd Rd(11)&Rd(11...1), CRd(0) Rd 0 (EOR Rd, Rd) Rd (2 n‐1)‐Rd Rd Rd 1
Arithmetic right shift Clear Complement (C1) Decrement
0011 ‐‐0d dddd 1100 EOR Rd, Rd 0011 ‐‐0d dddd 1010 0011 0d dddd 1001
Joan Oliver 14
DEC Rd INC Rd LSL Rd LSR Rd NEG Rd ROL Rd ROR Rd SWAP Rd
Rd Rd‐ 1 Rd Rd+ Rd Rd(10...0) & 0, CRd(11) Rd 0&Rd(11...1), CRd(0) Rd 2 n‐Rd RdRd(10...0) & C, CRd(11) Rd C & Rd(11...1), C Rd(0) Rd Rd(3...0) & Rd(11...4)
Decrement Increment Left shift Right shift Negation(C2) Left rotation Right rotation 4 ‐bit right rotation without carry
0011 ‐‐0d dddd 1001 0011 ‐‐0d dddd 1000 ADD Rd, Rd 0011 ‐‐0d dddd 1101 0011 ‐‐0d dddd 1011 0011 ‐‐0d dddd 1111 0011 ‐‐0d dddd 1110 0011 –1 d dddd ‐‐‐‐
Instruction Status Code Words Cycles
LDI Rd, k ADDI Rd, k ANDI Rd, k
Rd k Rd Rd+k Rd Rdk
Load with immediate Add with immediate Logical and with immediate
0011 ‐‐‐d dddd 0000 0011 ‐‐‐d dddd 0001 0011 ‐‐‐d dddd 0010
WhatWhat instructions?instructions? WhatWhat dodo theythey do?do? InstructionInstruction setset (II)(II)
ANDI Rd, k CPI Rd, k ORI Rd, k SBCI Rd, k SUBI Rd, k TSTI Rd, k
Rd Rdk ‐ Rd‐k Rd Rdk Rd Rd‐(k+C) Rd Rd‐k ‐ Rdk
Logical and with immediate Compare with immediate Logical or with immediate Subtract with carry with immediate Subtract with immediate And test with immediate
0011 d dddd 0010 0011 ‐‐‐d dddd 0110 0011 ‐‐‐d dddd 0011 0011 ‐‐‐d dddd 0101 0011 ‐‐‐d dddd 0100 0011 ‐‐‐d dddd 0111
BRBC b, k BRBS b, k BRCC k BRCS k ...BRSH k
Si SR(s)=0 aleshores PC PC+k+ Si SR(s)=1 aleshores PC PC+k+ Si C=0 aleshores PC PC+k+ Si C=1 aleshores PC PC+k+ Si C=0 aleshores PC PC+k+
Jump if Status Register bit b is 0 Jump if Status Register bit b is 1 Jump if carry is 0 Jump if carry is 1 Jump if equal or greater
1111 kkkk kkkk kbbb 1110 kkkk kkkk kbbb 1111 kkkk kkkk k 1110 kkkk kkkk k 1111 kkkk kkkk k
Joan Oliver 15
...BRLO k ...BRNZ k, BRNE k ...BRZE k, BREQ k ...BRPL k ...BRMI k BRVC k BRVS k BRID k BRIE k
Si C=1 aleshores PC PC+k+ Si Z=0 aleshores PC PC+k+ Si Z=1 aleshores PC PC+k+ Si N=0 aleshores PC PC+k+ Si N=1 aleshores PC PC+k+ Si V=0 aleshores PC PC+k+ Si V=1 aleshores PC PC+k+ Si I=0 aleshores PC PC+k+ Si I=1 aleshores PC PC+k+
Jump if minor Jump if different Jump if equal Jump if positive Jump if negative Jump if overflow cleared Jump if overflow set Jump If interruption disabled Jump if interruption enabled
1110 kkkk kkkk k 1111 kkkk kkkk k 1110 kkkk kkkk k 1111 kkkk kkkk k 1110 kkkk kkkk k 1111 kkkk kkkk k 1110 kkkk kkkk k 1111 kkkk kkkk k 1110 kkkk kkkk k
WhatWhat instructions?instructions? WhatWhat dodo theythey do?do? InstructionInstruction setset (III)(III)
Instruction Code Words Cycles
ICALL z (o y o x ) IJMP z (o y o x ) RCALL k RJMP k
Pila PC, PC Z, SP SP + PC Z Pila PC, PC PC + k+1, SP SP + PC PC + k+
Indirect jump to subroutine Indirect jump Indirect call to subroutine Relative jump
0110 zyx‐ ‐‐‐‐ 0011 0110 zyx‐ ‐‐‐‐ 0010 0101 kkkk kkkk kkkk 0100 kkkk kkkk kkkk
RJMP k 3 RET RETI
PC PC + k+ SP SP‐1, PC pila SP SP‐1, PC pila
Relative jump Return from subroutine Return from ISR
0100 kkkk kkkk kkkk 0110 000 ‐ ‐‐‐‐ 0100 0110 000 ‐ ‐‐‐‐ 0101
Load instructions (with memory) LPM Rd, Z (o Y o X) LPM Rd, +Z (o Y o X) LPM Rd, ‐Z (o Y o X)
Rd mem(Z), (o Y o X) Z Z+1, Rd mem(Z), (o Y o X) Z Z‐1, Rd mem(Z), (o Y o X)
Immediate load Indirect load with pre‐increment Indirect load with pre‐decrement
1100 zyxd dddd 1100 1100 zyxd dddd 1101 1100 zyxd dddd 1111
LDS Rd, K LD Rd, Z (o Y o X) LD Rd, +Z (o Y o X) LD Rd, ‐Z (o Y o X) LDD Rd Z
Rd (K) Rd mem(Z), (o Y o X) Z Z+1, Rd mem(Z), (o Y o X) Z Z‐1, Rd mem(Z), (o Y o X) Rd (Z )
Direct load (double word) Indirect load Indirect load with pre‐increment Indirect load with pre‐decrement I di l d i h di l i Z
1100 ‐‐‐d dddd 0100 1100 zyxd dddd 0000 1100 zyxd dddd 0001 1100 zyxd dddd 0011 1000 d dddd
Joan Oliver 16
LDD Rd, Z+q LDD Rd, Y+q STS K, Rs ST Z (o Y o X) , Rs ST +Z (o Y o X), Rs ST ‐Z (o Y o X), Rs STD Z+q, Rs STD Y+q, Rs
Rd mem(Z+q) Rd mem(Y+q) mem(K) Rs mem(Z) Rs, (o Y o X) Z Z+1, mem(Z) Rs, (o Y o X) Z Z‐1, mem(Z) Rs, (o Y o X) (Z+q) Rs (Y+q) Rs
Indirect load with displacement in Z Indirect load with displacement in Y Direct store (double word) Indirect store Indirect store with pre‐increment Indirect store with pre‐decrement Indirect store with displacement in Z Indirect store with displacement in Y
1000 qqqd dddd qqqq 1010 qqqd dddd qqqq 1101 ‐‐‐d dddd 0100 1101 zyxd dddd 0000 1101 zyxd dddd 0001 1101 zyxd dddd 0011 1001 qqqd dddd qqqq 1011 qqqd dddd qqqq
asmEDUp12:asmEDUp12: ExampleExample
.DEF tmp = R16; begin: RCALL wait; IN tmp, PORTE; ANDI tmp, 0x002;
BRZE begin;
( 0, "0101000000000111"), ‐‐ 0x5007 ‐ rcall 7 ( 1, "0111000100000010"), ‐‐ 0x7102 ‐ in r16 000010 ( 2, "0011000100000010"), ‐‐ 0x3102 ‐ andi r16 0x ( 3, "0000000000000010"), ‐‐ 0x ( 4, "1110111111011001"), ‐‐ 0 xEFD9 ‐ brze ‐ 5
Joan Oliver 19
R begin; IN tmp, PORTA; OUT PORTB, tmp; RJMP begin; ‐‐Bucle d'espera wait: LDI tmp, 0xFFF;
loop: DEC tmp; BRNZ loop; RET;
( 4, 0 0 00 ), 0x F 9 br e 5 ( 5, "0111000100000000"), ‐‐ 0x7100 ‐ in r16 000000 ( 6, "0111100100000001"), ‐‐ 0x7901 ‐ out 000001 r ( 7, "0100111111111000"), ‐‐ 0x4FF8 ‐ rjmp ‐ 8
( 8, "0011000100000000"), ‐‐ 0x3100 ‐ ldi r16 0xfff ( 9, "0000111111111111"), ‐‐ 0xFFF (10, "0011000100001001"), ‐‐ 0x3109 ‐ dec r (11, "1111111111110001"), ‐‐ 0xFFF1 ‐ brnz ‐ 2 (12, "0110000000000100"), ‐‐ 0x6004 – ret
InstructionInstruction cyclecycle or,or, howhow EduP12EduP12 works?works?
Joan Oliver 20
InstructionInstruction cyclecycle or,or, howhow EduP12EduP12 works?works? ADDADD Rd,Rd, RsRs
ADD instruction code: R17 R17+ R 0000 10sd dddd ssss 0000 1011 0001 0000
Cicle PC MAR IR R17 R16 State OpA OpB OpCod
Joan Oliver 21
Cicle PC MAR IR R17 R16 State OpA OpB OpCod
Starting 100 ‐ ‐ 0x300 0x500 0b00000 ‐ ‐ ‐
Cycle 1 100 100 ‐ 0x300 0x500 0b00000 ‐ ‐ ‐
Cycle 2 101 100 0x0B10 0x300 0x500 0b00000 PC ‐ INC
Cycle 3 101 100 0x0B10 0x800 0x500 0b01100 Rd Rs ADD
InstructionInstruction cyclecycle or,or, howhow EduP12EduP12 works?works? BRMIBRMI
Next instruction is a conditional branch.
In fact, stored program corresponds to:
BRMI loop
BRMI instruction format:
Joan Oliver 22
Cicle PC MAR IR R17 R16 Estat OpA OpB CodOp Inicial 101 100 0x0B10 800 500 0b01100 ‐ ‐ ‐ Cicle 1 101 101 0x0B10 800 500 0b01100 ‐ ‐ ‐ Cicle 2 102 101 0xEFF2 800 500 0b01100 PC ‐ INC Cicle 3()* 100 101 0xEFF2 800 500 0b01100 PC k ADD
AddressingAddressing modesmodes
Joan Oliver 25
AddressingAddressing modesmodes (II)(II)
Joan Oliver 26
EduP12:EduP12: WorkingWorking withwith datadata InstructionsInstructions LD/STLD/ST
Direct (double word)
Direct load Direct store
LDS Rd, K STS K, Rs
Rd (K) mem(K) Rs
1100 ---d dddd 0100 1101 ---d dddd 0100
Indirect
Indirect load I di t t
LD Rd, Z (o Y o X) ST Z ( Y X) R
Rd mem(Z), (o Y o X) (Z) R ( Y X)
1100 zyxd dddd 0000 1101 d dddd 0000
Direct format Opcode Source/Destination
Operands
K
Joan Oliver 27
Indirect format Opcode Destination / [ ] Source / [ ]
Operands
Indirect store ST Z (o Y o X) , Rs mem(Z) Rs, (o Y o X) 1101 zyxd dddd 0000
SubroutinesSubroutines
RET: 0110 0000 ---- 0100
RCALL K: 0101 KKKKKKKKKKKK
Joan Oliver 28
Input/outputInput/output inin EduP12:EduP12: PeripheralsPeripherals
Input port Output port
Joan Oliver 31
ExamplesExamples
Joan Oliver 32
ExamplesExamples
Joan Oliver 33