일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- c++
- 소수
- CSS
- 백준
- series
- 알고리즘
- 상태
- 포토샵
- align-items
- 수학
- skt membership
- spring
- Photoshop
- 강화학습
- Gap
- 에라토스테네스의 체
- grid
- 통신사할인
- 확률
- dataframe
- stl
- SK바이오사이언스
- c
- pandas
- Design Pattern
- Flexbox
- margin
- Codility
- Prefix Sums
- Javascript
Archives
- Today
- Total
sliver__
2.9 Communicating with People 본문
728x90
Quiz) 아래 코드를 assembly language로 바꾸면?
void strcpy (char x[], char y[])
{
int i;
i = 0;
while ((x[i] = y[i]) != ‘\0’) /* copy & test byte */
i += 1;
}
==>
strcpy:
addi $sp, $sp, -4
sw $s0, 0($sp)
add $s0, $zero, $zero
L1:
add $t1, $s0, $a1 # address of y[i] in $t1
lbu $t2, 0($t1)
add $t3, $s0, $a0
sb $t2, 0($t3)
beq $t2, $zero, L2 # y[i] == 0, go to L2
addi $s0, $s0, 1
j L1
L2:
lw $s0, 0($sp) # Restore $s0 from memory
addi $sp, $sp, 4 # Pop 1 word off stack
jr $ra
Characters and Strings in Java
16 bit를 load / store 하는 명령어는 Load half(lh).
lh는 half word를 memory에서 가져오고 reigster의 오른쪽 16bit에 저장.
signed number인 경우, signed extends를 통해 왼쪽 16비트에 채움
unsigned 16bits 명령어를 lhu.
store half word(sh)는 register의 오른쪽 16비트를 memory에 저장
ex) lhu $t0, 0($sp)
sh $t0, 0($gp)
!! C string의 경우 char이지만 align 을 위해 4bytes(word)를 점유한다.
728x90
'CS > 컴퓨터 구조' 카테고리의 다른 글
2.11 Parallelism and Instructions : Synchronization (0) | 2023.10.21 |
---|---|
2.10 MIPS Addressing for 32-bit immediates and Addresses (1) | 2023.10.21 |
2.8 Supporting Procedures in Computer Hardware (0) | 2023.10.21 |
2.7 Instructions for Making decision (0) | 2023.10.20 |
2.6 Logical Operations (0) | 2023.10.20 |
Comments