csse 232 computer architecture i - rose-hulman.edu€¦ · hello world in x86 for linux section...
TRANSCRIPT
![Page 1: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/1.jpg)
CSSE 232Computer Architecture I
Other Architectures
1 / 22
![Page 2: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/2.jpg)
Class Status
Reading for today
• 2.16-17
2 / 22
![Page 3: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/3.jpg)
Outline
• Load-store
• Accumulator
• Memory-to-Memory
• Stack
• Advantages/Disadvantages
3 / 22
![Page 4: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/4.jpg)
Load-Store architectures
• All operations occur in registers
• Register-to-register instructions have three operands perinstruction
• Special instructions to access main memory
4 / 22
![Page 5: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/5.jpg)
Other Architectures
• Accumulator
• Memory-to-memory
• Stack
5 / 22
![Page 6: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/6.jpg)
Accumulator Architecture
• All operations use an accumulator register
• Operands come from the accumulator or memory
• Result of most operations is stored in the accumulator
6 / 22
![Page 7: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/7.jpg)
Memory-to-Memory Architecture
• Similar to load-store architectures, but no registers
• All three operands of each instruction are in memory
7 / 22
![Page 8: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/8.jpg)
Stack Architecture
• All operations occur on top of the stack
• Only push and pop access memory
• All other instructions remove their operands from the stackand replace them with the result
• The implementation uses a stack for the top two entries
• Accesses that use other stack positions are memory references
8 / 22
![Page 9: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/9.jpg)
Examples
• Want to execute the statementa = b + c;
• a, b, and c are variables in memory
9 / 22
![Page 10: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/10.jpg)
Accumulator
load AddressB # Acc = Memory[AddrB] or Acc = B
add AddressC # Acc = B + Memory[AddrC] or Acc = B + C
store AddressA # Memory[AddrA] = Acc or A = B + C
10 / 22
![Page 11: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/11.jpg)
Accumulator
load AddressB # Acc = Memory[AddrB] or Acc = B
add AddressC # Acc = B + Memory[AddrC] or Acc = B + C
store AddressA # Memory[AddrA] = Acc or A = B + C
10 / 22
![Page 12: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/12.jpg)
Memory-to-Memory
add AddressA, AddressB, AddressC
11 / 22
![Page 13: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/13.jpg)
Memory-to-Memory
add AddressA, AddressB, AddressC
11 / 22
![Page 14: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/14.jpg)
Stack
push AddressC # Top = Top+4; Stack[Top] = Memory[AddrC]
push AddressB # Top = Top+4; Stack[Top] = Memory[AddrB]
add # Stack[Top-4] = Stack[Top] + Stack[Top-4];
# Top = Top-4
pop AddressA # Memory[AddrA] = Stack[Top]; Top = Top - 4
12 / 22
![Page 15: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/15.jpg)
Stack
push AddressC # Top = Top+4; Stack[Top] = Memory[AddrC]
push AddressB # Top = Top+4; Stack[Top] = Memory[AddrB]
add # Stack[Top-4] = Stack[Top] + Stack[Top-4];
# Top = Top-4
pop AddressA # Memory[AddrA] = Stack[Top]; Top = Top - 4
12 / 22
![Page 16: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/16.jpg)
Load-Store
load r1 AddressB # r1 = Memory[AddressB]
load r2 AddressC # r2 = Memory[AddressC]
add r3 r1 r2 # r3 = r1 + r2
store r3 AddressA # Memory[AddressA] = r3
13 / 22
![Page 17: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/17.jpg)
Load-Store
load r1 AddressB # r1 = Memory[AddressB]
load r2 AddressC # r2 = Memory[AddressC]
add r3 r1 r2 # r3 = r1 + r2
store r3 AddressA # Memory[AddressA] = r3
13 / 22
![Page 18: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/18.jpg)
Group Assignment
• What do you think are the advantages/disadvantages of eachof the types of architectures?
14 / 22
![Page 19: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/19.jpg)
Advantages and Disadvantages
• Stack Advantages• Short instructions.
• Stack Disadvantages• A stack can’t be randomly accessed• Hard to generate efficient code• The stack itself is accessed every operation and becomes a
bottleneck
• Accumulator Advantages• Short instructions
• Accumulator Disadvantages• The accumulator is only temporary storage so memory traffic
is the high for this approach.
15 / 22
![Page 20: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/20.jpg)
Advantages and Disadvantages
• Load-Store Advantages• Makes code generation easy• Data can be stored for long periods in registers.
• Load-Store Disadvantages• All operands must be named leading to longer instructions.
• Memory-to-Memory Advantages• Simple processor design
• Memory-to-Memory Disadvantages• Same as L+S• Bottleneck at memory access
16 / 22
![Page 21: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/21.jpg)
Alternative designs
Complete Instruction Set Computer (CISC)
• Examples• IBM 360, DEC VAX, Intel 80x86, Motorola 68xxx
• Features• Varying instruction lengths• Memory locations as operands• Source operand is also the destination
Reduced Instruction Set Computer (RISC)
• Examples• MIPS, Alpha, PowerPC, SPARC
• Load/store
• Same instruction lengths
• Longer code programs
17 / 22
![Page 22: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/22.jpg)
Hello world in x86 for Linux
section . d a t a ; s e c t i o n f o r i n i t i a l i z e d datas t r : db ' He l l o wor ld ! ' , 0Ah ; message wi th new− l i n e at the endstr_len : equ $ − s t r ; c a l c s s t r i n g l e n g t h by s u b t r a c t i n g
; t h i s ' add r e s s ( $ ) from s t r i n g add r e s s
section .text ; t h i s i s the code s e c t i o nglobal _start ; s t a r t i s the e n t r y po i n t_start : ; p r o c edu r e s t a r t
mov eax , 4 ; s p e c i f y the s y s w r i t e f u n c t i o n codemov ebx , 1 ; s p e c i f y f i l e d e s c r i p t o r s t dou tmov ecx , s t r ; move s t r i n g s t a r t a dd r e s s to ecx r e g i s t e rmov edx , str_len ; move l e n g t h o f messagei n t 80h ; t e l l k e r n e l to per fo rm the system c a l lmov eax , 1 ; s p e c i f y s y s e x i t f u n c t i o n codemov ebx , 0 ; s p e c i f y r e t u r n code f o r OSi n t 80h ; t e l l k e r n e l to per fo rm system c a l l
18 / 22
![Page 23: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/23.jpg)
Hello world in MIPS for SPIM
. datamsg : . asciiz ”Hello , world ! ”. text. globl main
main :l a $a0 , msgl i $v0 , 4s y s c a l lj r $ra
19 / 22
![Page 24: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/24.jpg)
Hello world in PS2 MIPS for Linux
# h e l l o . S by Spencer T. Pa rk in
. rdata # beg in read−on l y data segment
. align 2 # because o f the way memory i s b u i l thello : . asciz ”Hello , world !\ n” # a n u l l t e rm ina t ed s t r i n g
. align 4 # because o f the way memory i s b u i l tlength : . word . − hello # leng t h = IC − ( h e l l o−addr )
. text # beg in code segment
. globl main # f o r gcc / l d l i n k i n g
. ent main # f o r gdb debugg ing i n f o .main :
move a0 , $0 # load s tdou t fdl a a1 , hello # load s t r i n g add r e s slw a2 , length # load s t r i n g l e n g t hl i v0 , __NR_write # s p e c i f y system w r i t e s e r v i c es y s c a l l # c a l l the k e r n e l ( w r i t e s t r i n g )l i v0 , 0 # load r e t u r n codej ra # re t u r n to c a l l e r. end main # f o r dgb debugg ing i n f o .
From http://tldp.org/HOWTO/Assembly-HOWTO/mips.html
20 / 22
![Page 25: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/25.jpg)
Review and Questions
• Load-store
• Accumulator
• Memory-to-Memory
• Stack
• Advantages/Disadvantages
21 / 22
![Page 26: CSSE 232 Computer Architecture I - rose-hulman.edu€¦ · Hello world in x86 for Linux section .data;sectionfori n i t i a l i z e ddata str:db ' Helloworld! ' , 0Ah;messagewithnew](https://reader034.vdocuments.mx/reader034/viewer/2022050108/5f46129b241dfe02431a0cb9/html5/thumbnails/26.jpg)
Project time
Work on relprime()
22 / 22