INTRO.
* Instruction 명령어
Opcode + operand specifier
* Instruction set 명령어 전체를 아우르는 말
* RISC
- ex. mips
* CISC
- 복잡한 일을 한 문장에 하게 되어 장문인 경우가 많음
- ex. intel
* 오늘날은 RISC와 CISC의 구분이 모호함
CPU는 "단순하면서도 성능이 좋게 되는 것"을 목적으로 함
OPERATION OF THE COMPUTER HARDWARE.
* add a, b, c <==> a = b + c
* sub a, b, c <==> a = b - c
EX) f = ( g + h ) - ( i + j )
add t0, g , h <==> t0 = g + h
add t1, i , j <==> t1 = i + j
sub f , t0 , t1 <==> f = t0 - t1 = ( g + h ) - ( i + j )
※ 매개변수의 순서는 프로세서마다 다 다름.
예) add a , b , c 에 대해
프로세서 1. c = a + b
프로세서 2. a = b + c
본 강의에서는 위와 같은 기준으로 함
OPERANDS OF THE COMPUTER HARDWARE.
*Arithmetic intruction's operands must be registers - only 32 registers provided
코드 내에 있는 많은 변수들을 컴파일러가 메모리를 적절히 활용하여 32개 내에서 처리할 수 있도록 한다.
*MIPS Register
- 32 registers
- variable
- $s0, $s1, $s2, ... $s7
- temporary registers
- $t0, $t1, $t2, ... $t9
※ 변수명은 conventional 한거
EX) f = ( g + h ) - ( i + j ) ;
int f, g, h, i, j;
f , g , h , i , j ---mapping---> $s0, $s1, $s2, $s3, $s4
ans)
※c코드의 변수가 mips variable로 치환
add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1\
MEMORY OPERANDS.
* Arrays and structures
* Data transfer instructions
load : lw(load word) in MIPS
store : sw(store word) in MIPS
EX) g = h + A[8]
base address of A -> $s3
int g, h, A[100];
ans)
lw $t0, 32($s3) // $t0 gets A[8]
add $s1, $s2, $t0 // g = h + A[8]
32($s3) ==> (offset)((base)) ~ offset은 4의 배수여야함.
32($s3)은 *(a+32)가 아니라 *((char*)a+32)이므로 A[8]이라 할 수 있다.
HARDWARE/SOFTWARE INTERFACE.
* Byte addressing - 보통 바이트 단위로 addressing
* Alignment restriction (aka memory alignment) - 워드 단위로 align ~ process의 접근을 용이하게 하기 위함
ex.
struct{ char a, int b, char c, char d} ~~~ 10바이트 ~ 12바이트
struct { char a, char b, char c, int d} ~~~ 8바이트
* Endianness
- Little endian
using address of the rightmost ~
ex. intel IA-32, DEC PDP 11...
- Big endian
using address of the leftmost ~
ex. MIPS, IBM ...
EX)
* Endianness and store
* Endianness and load
EX) A[12] = h + A[8];
- base address of A -> $s3
- h -> $s2
ans)
lw $t0, 32($s3) // Temporary reg. $t0 gets A[8]
add $t0, $s2, $t0 // Temporary reg. $t0 gets h+A[8]
sw $t0, 48($s3) // Stores h+A[8] back into A[12]
CONSTANT OR IMMEDIATE OPERANDS.
* Constant operands
* Adding 4 to $s3 without constant operand
"a = b + 3"
lw $t0, AddrConstatnt3($s1) // $t0 = constatn 3
add $s3, $s3, $t0 // $s3 = $s3 + t0
* Faster version (개선)
"a = b + 3"
addi( add immediate ) instruction
addi $s3, $s3, 4 // $s3 = $s3 + 4
'Computers > Computer Architecture' 카테고리의 다른 글
lecture 5. History of ISA (0) | 2014.01.29 |
---|---|
lecture 4. Addressing Modes (0) | 2014.01.29 |
lecture3. Machine instructions (0) | 2014.01.29 |