YYYEJI

[MacOS] MIPS assembly language 알아보기 본문

Computer architectures

[MacOS] MIPS assembly language 알아보기

YEJI ⍢ 2022. 10. 8. 00:17
728x90

 

아래 코드를 가지고 설명하겠습니다.

✓   코드를 작성할 땐 textEdit(메모장), visual Studio 등을 사용하시면 됩니다.

 

 

↓↓↓      C language code      ↓↓↓

#include <stdio.h>

int main(){
    printf("Hello World!!!\n");
    return 0;
}

↓↓↓       Assembly language code     ↓↓↓

# test.s
# print "Hello World!!!"
.data
    str: .asciiz "\nHello, World!\n"

.text
main:
    li $v0, 4
    la $a0, str
    syscall

    li $v0, 10
    syscall

 

pseudo assembly instruction

MIPS 언어에는 pseudo assembly instruction이 존재합니다.

(실제로 존재하지 않지만 사용하면 MIPS가 알아서 실행시켜 줍니다)

li      $rs,   immed

(Load immediate vlaue(immed) to s$rs)

la      $rs,   immed

(Load address(addr) to $rs)

 

 

 

data part

str. .asciiz "Heelo World!!!"

✓   str.은 변수라고 생각해도 좋고, 위치라고 생각해도 좋습니다.

✓   .asciiz는 "" doucle quote를 사용하겠다는 의미입니다.

 

 

 

syscall - System Call 

System services

✓   System call code에 따라 실행되는 결과가 달라집니다.

✓   우리가 사용한 코드에서는 4를 사용했습니다. 

✓ 위에 표를 보면 4는 print_string이기 때문에 .str을 출력해줍니다.

 

 

 

코드를 실행시킨 화면입니다.

 

 

 

Breakpoint 란?

MIPS는 실행 후 에러가 뜬 부분에서 멈춰서 디버깅할 수 있게 해줍니다.

 

 

 

 

◡̈

 

 

 

'Computer architectures' 카테고리의 다른 글

[MIPS] Three MIPS Instruction Format  (0) 2022.10.10
[MIPS] MIPS Instruction Summary  (0) 2022.10.10
[MacOS] QtSpim 사용하기  (0) 2022.10.07
[MacOS] QtSpim 설치하기  (0) 2022.10.07
[MIPS] Control Instruction  (2) 2022.09.25