MIPS Programing Model 및 프로그램

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 실 습실 습 1.
Advertisements

1 Prof. Young Jin Nam, Daegu University 컴퓨터 구조 (Computer Architecture) 명령어 세트 : 특성과 기능 남영진
컴퓨터의 구조 2006년 2학기 컴퓨터의 개념 및 실습.
ISA 심화 및 start.S code 분석 SIOR 15th 최재훈.
C++ Tutorial 1 서강대학교 데이터베이스 연구실.
Basic of Buffer Over Flow
Sources of the Magnetic Field
Chapter 7 ARP and RARP.
Linux/UNIX Programming APUE (The Environment of a UNIX Process)
제8장. RISC 및 슈퍼스칼라 프로세서 8.1 RISC의 출현 동기 8.2 RISC의 발전 경위
4장 어셈블리 프로그램 작성의 기본 어셈블러 어셈블리 언어 요소 예제 프로그램 데이터 정의
SAP QUERY SAP R/3 4.6C.
1. 컴파일러 개론 1-1. Compiler 정의 1-2. Language Processing System
기본 컴퓨터 프로그래밍 Lecture #6.
C 프로그래밍 소개 숙명여대 창병모 2011 가을.
Operating Systems Overview
컴퓨터구조 – 중간시험 (답안지) 부분점수 (사소한 실수면 -1)
7장 : 캐시와 메모리.
Power Java 제4장 자바 프로그래밍 기초.
7장 마이크로프로세서의 명령어수행과 주소지정 방식 Slide 1 (of 29).
출처: IT CookBook, 컴퓨터 구조와 원리 2.0 제 12장
PowerPC ABI 김종화.
4장. 컴퓨터 시스템의 구성과 기능 다루는 내용 컴퓨터 분해를 통한 본체 살펴보기 컴퓨터 구성요소 컴퓨터의 기능
버퍼 오버플로우 시스템보안 인터넷공학전공 권영락.
Embedded System Porting (2)
9장. 중앙처리 장치의 조직과 기능 다루는 내용 컴퓨터 본체에서 CPU의 위치 살펴보기 CPU의 성능, 기능, 조직
1 마이크로프로세서의 원리 마이크로컨트롤러 AVR ATmega128.
Dynamic Programming.
Computer Architecture
어셈블리어 및 실습 금 1,2 (314) / 금 3,4 (307) RTDCS 이 종 태
Chapter 06 명령어와 번지지정 방식.
8086 프로세서의 구조 및 동작 방식 시스템 프로그래밍 - Lecture #2 신라대학교 컴퓨터공학과 시스템 프로그래밍.
PLC.
제 2 장 변수와 상수.
임베디드 소프트웨어 설계.
10장. 중앙처리 장치의 명령어 다루는 내용 어셈블리 프로그램의 이해 인터럽트(interrupt) 명령어 세트 주소 지정 방식.
Chapter 4 The Von Neumann Model.
adopted from KNK C Programming : A Modern Approach
컴퓨터 시스템 개관 시스템 프로그래밍 - Lecture #1 신라대학교 컴퓨터공학과 시스템 프로그래밍.
Chapter 2 Lexical Elements, Operators, and the C System
UNIT 07 Memory Map 로봇 SW 교육원 조용수.
Linux/UNIX Programming
Computer System Architecture
A Web-Based Little Man Computer Simulator
Formatted Input/Output
운영체제 (Operating Systems) (Memory Management Strategies)
Introduction to Programming Language
Transmission Control Protocol (TCP)
User Datagram Protocol (UDP)
1. 컴퓨터 시스템 구성요소 메모리(Memory) 캐시메모리 개념 캐시메모리의 특징 적중률(hit ratio)
Chapter 12 Memory Organization
Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2.
문자열 처리하기 working with Strings
Operating System Multiple Access Chatting Program using Multithread
4. 어휘 분석(Lexical analysis)
누구나 즐기는 C언어 콘서트 제2장 기초 사항 IT응용시스템공학과 김형진 교수.
Signature, Strong Typing
Signature, Strong Typing
Signature, Strong Typing
작동 원리 Keypad 박민호.
점화와 응용 (Recurrence and Its Applications)
Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2.
ARM Development Suite v1.2
Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2.
Introduction to Computer System 컴퓨터의 이해 3: 데이터 표현
C.
Machine architecture Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Chapter 2.
Lecture 7 7-Segment LED controller using u-controller
ARM Development Suite v1.2
4-1. 명령어 형식.
Presentation transcript:

MIPS Programing Model 및 프로그램 Hoon Oh

MIPS Memory Layout Memory organization Memory consists of a number of cells, each of which holds one byte. Memory cells are numbered sequentially from zero up to the maximum allowable size. Address space Text segment holds instructions for a program Data segment Static data Dynamic data Grows upward after static data. Stack Resides in the top of the address space and grows downward.

(data that instructions MIPS Memory Layout ($sp) 0x7fffffff Stack segment 0x00000000 0x00 0x00000001 0xA0 0x00000002 0x3E 0x00000003 0x10 Dynamic data 0xFFFFFFFC 0x90 ($gp) 0x10008000 0xFFFFFFFD 0x6F Data segment (data that instructions operate on) 0xFFFFFFFE 0xA1 0xFFFFFFFF 0x00 0x10000000 Text segment (Instructions) Memory Organization ($pc) 0x00400000 reserved MIPS Memory Layout

MIPS registers MIPS processor contains 32 general purpose registers (numbered 0 – 31). Register n is designated by $n or Rn. $zero (0) is always set to 0. $at (1), $k0 (26) and $k1 (27) are reserved for use by the assembler and OS. $v0 and $v1 (2, 3) are used for return values. $t0 - $t9 (8-15, 24, 25) are used for temporary values. $s0 - $s7(16-23) are used for long-lived values. $gp, $sp, $fp, $ra are used for special purposes, as shown in the table of the next page.

MIPS Registers Register name Number Usage zero constant 0 at 1 constant 0 at 1 reserved for assembler v0, v1 2 ~ 3 expression evaluation and results of a function a0 ~ a3 4 ~ 7 arguments 1 - 4 t0 ~ t7 8 ~ 15 temporary (not preserved across call) s0 ~ s7 16 ~ 23 saved (preserved across call) t8, t9 24, 25 temporary (not preserved across call) k0, k1 26, 27 reserved for OS kernel gp 28 pointer for global area sp 29 stack pointer fp 30 frame pointer ra 31 return address (used by function call)

SPIM Simulator SPIM Simulator that runs programs written for MIPS R2000/R3000 processors Advantages to using a machine simulator MIPS workstation are not generally available. Provides better environment for low-level programming than an actual machine: detect more errors provide more features give convenient edit-assemble-load development cycle, compared to using a circuit board. easy to identify and fix the bugs. Disadvantages The programs run slower than on a real machine.

OS system calls An application program asks the kernel to do I/O by making system calls. The kernel implements these system calls by talking directly to the hardware. Application programs Kernel Hardware Programs make system calls asking kernel to do I/O Kernel controls I/O devices directly

SPIM’s system calls SPIM provides a small set of 10 OS-like system services through the system call (syscall) instruction. Service Call code Arguments Results print_int 1 $a0 = integer print_float 2 $f12 = float print_double 3 $f12 = double print_string 4 $a0 = string read_int 5 integer (in $v0) read_float 6 float (in $f0) read_double 7 double (in $f0) read_string 8 $a0 = buffer, $a1 = length sbrk 9 $a0 = amount address (in $v0) exit 10 $v0 : system call code $a0...$a3 : arguments ($f12 <- floating point values) syscall (initiate system service) $v0 :results ($f0: for the floating point)

Code Format Source code format [label:] operation [operand], [operand], [operand] [#comment] Brackets ([ ]) indicates an optional field. Constants Hex numbers: prefix with 0x String: “hello world\n” Special characters: \n (newline), \t (tab), \” (quote). SPIM directives for character strings .ascii “abcd” : do not null-terminate them. .asciiz “abcd”: null-terminate them.

Code Format: hello.a ## hello.a – prints out “hello world” ## a0 – points to the string ################################################################### # text segment # .text .globl __start __start: # execution starts here la $a0, str # put string address into a0 li $v0, 4 # system call to print syscall # out a string li $v0, 10 syscall # au revoir ... # data segment # .data str: .asciiz “hello world\n” ## ## end of file hello.a

PC-SPIM for Windows Registers window Text segment Data Segment Messages window

Inside text & data segments [0x00400000] 0x3c011001 lui $1, 4097 [str] ;9: la $a0, #str put string .. [0x00400004] 0x34200000 ori $4, $1, 0 [str] [0x00400008] 0x34020004 ori $2, $0, 4 ;10: li $v0, #system call to .. [0x0040000c] 0x0000000c syscall ;11; syscall [0x00400010] 0x3402000a ori $s2, $0, 10 ;13; li $v0, 10 [0x00400014] 0x0000000c syscall ;14; syscall text segment DATA [0x10000000] ... [0x000fffx] 0x00000000 [0x1000fffc] 0x00000000 [0x10010000] 0x6c6c6568 0x6f77206f 0x0a646c72 0x00000000 [0x10010010] ... [0x10020000] 0x00000000 STACK [0x7fffaffc] 0x00000000 data segment

MIPS 산술연산 예 Instruction Example Comments Add add $t1, $t2, $t3 Add immediate addi $t1, $t2, 50 # $t1 = $t2 + 50 Subtract sub $t1, $t2, $t3 # $t1 = $t2 - $t3 Multiply mult $t2, $t3 # Hi, Lo = $t2 x $t3 Divide div $t2, $t3 # Lo = $t2 / $t3 # Hi = $t2 mod $t3 Move from Hi mfhi $t1 # $t1 = Hi # get copy of Hi Move from Li mflo $t1 # $t1 = Lo # get copy of Lo

Programming Example: temp.a ## temp.a ask user for temperature in Celsius. ## convert to Fahrenheit, print the result. (F = 9C/5 + 32) ## v0 – reads in Celsius ## t0 – holds Fahrenheit result ## a0 – points to output strings ############################################################ # text segment # .text .globl __start __start: la $a0, prompt # print prompt on terminal li $v0,4 syscall li $v0,5 # syscall 5 reads an integer mul $t0,$v0,9 # to convert,multiply by 9, div $t0,$t0,5 # divide by 5, then add $t0,$t0,32 # add 32

temp.a (cont...) la $a0,ans1 # print string before result li $v0,4 syscall mov $a0,$t0 # print result move $a0,endl # system call to print li $v0,4 # out a newline li $v0,10 syscall # au revoir ... ############################################################## # data segment # .data prompt: .asciiz “Enter temperature (Celsius): “ ans1: .asciiz “The temperature in Fahrenheit is “ end1: .asciiz “\n“ ## end of file temp.a

math1.a ## Question: calculate A * X^2 + B * X + C ## Output format: "answer =180" ############################################################## # text segment # .text .globl __start __start: # execution starts here # Any changes outside of two dashed lines will be discarded # by mipsmark. put your answer between dashed lines. # ------------------ start cut -------------------------- (해답) # ------------------ end cut ---------------------------- # data segment # .data X: .word 7 A: .word 3 B: .word 4 C: .word 5 ans: .asciiz “answer = “ endl: .anciiz “\n” ## End of file math1.a

Solution: math1.a # ------------------ start cut -------------------------- # This solution has a bug. Perform source level debugging to # single step through the code and locate the error. lw $t0, X lw $t1, A lw $t2, B lw $t3, C mul $t4, $t0, $t0 # t4 = X^2 mul $t4, $t4, $t1 # t4 = A * X^2 mul $t5, $2, $t0 # t5 = B * X add $t4, $t4, $t5 # t4 = A * X^2 + B * X add $t4, $t4, $t3 # t4 = A * X^2 + B * X + C la $a0, ans # system call to print li $v0, 4 # out string syscall move $a0, $t4 # print result on terminal li $v0, 1 move $a0, endl # system call to print li $v0, 4 # out a newline li $v0, 10 syscall # au revoir ... # ------------------ end cut ----------------------------

실습1 프로그램 math1.a의 해답에서 버그가 하나 존재한다. Step button을 사용하여 해답의 5번째 라인 (lw $t1, A) 이 수행된 후에 다음 레지스터의 내용을 체크하시오. PC, t0, t1, gp, sp 10번째 라인 (mul $t5, $2, $t0)이 수행되기 전 후에 다음 레지스터들의 내용을 체크하시오. PC t4, t5 실행 후에 t5의 내용이 B*X=4 x 7 = 28 (0x1C)인가? 에러를 수정한 후에 값이 180이 나오는 지를 체크 하시오. 다음을 계산하는 프로그램을 작성하고 실행하여 다음시간까지 제출하시오. 5 * X^2 – 3 X값은 7로 하시오. 계산 결과는 242입니다.

과제1 Machine 언어와 Asembly언어의 관계는 무엇인가? 일반 C프로그래밍에 비해 Assembly프로그램의 장.단점은 무엇인가? 컴퓨터가 5에서 3을 뺄 때 거치는 과정을 보이시오? RISC 프로세서의 기본적인 아이디어는 무엇인가? Program counter의 목적은 무엇인가? SPIM에서 Identifier (식별자) 를 만드는 룰은 무엇인가? Syntax error와 logical error의 차이점은 무엇인가? Single stepping의 목적은 무엇인가? Breakpoint는 무엇인가? hi 와 lo 레지스터는 무슨 목적으로 사용되는가? Assembly programming에서 comments와 indentation이 왜 그렇게 중요한가? la, lb, li, 그리고 lw 사이의 차이점은 무엇인가? 산술적/논리적인 명령의 Operand는 어떤 순서로 놓여져야 하는가?