1 간단한 C 프로그램 2004.04.26 김희자, 최정욱. 2 목차 예제 소스 코드 컴파일 어셈블리 언어 Dlite 디버거 수행.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS Calling Convention Chapter 2.7 Appendix A.6.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
SPRING 2015 QtSpim Demo & Tutorial. 2 By DGP Outline How to write your own MIPS assembly language program How to use QtSpim simulator.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
MIPS Assembly Language Programming
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
PCSpim Introduction. Register contentProgramMemory contentMessage.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
Procedure call frame: Hold values passed to a procedure as arguments
ECE 0142 Recitation #5.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Calling Conventions See: P&H 2.8, 2.12.
20/06/2015CSE1303 Part B lecture notes 1 Functions, part 2 Lecture B15 Lecture notes, section B15.
MIPS Assembler Programming
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
Computer Architecture and Design – ECEN 350 Part 4 [Some slides adapted from M. Irwin, D. Paterson and others]
Lecture 4. Miscellaneous Addressing Mode, Memory Map, Pointer, and ASCII Prof. Taeweon Suh Computer Science Education Korea University ECM534 Advanced.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See: P&H Appendix A1-2, A.3-4 and 2.12.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture # 1 SPIM & MIPS Programming. SPIM SPIM is a MIPS32 simulator that reads and executes assembly language program written for SPIM. Platform -Unix,
MicroComputer Engineering IntroLab1 page 1 Introduction Lab1  A crash course in assembler programming  Learn how a processor works!  Decode a coded.
Lec 4Systems Architecture1 Systems Architecture Lecture 4: Compilers, Assemblers, Linkers & Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Intro to SPIM Justin Fiore Nathan Parish. Installing SPIM on Windows Download pcspim.zip from the SPIM website:
Report1 Sim-profile 을 이용한 LI 벤치마크 과목명 : 컴퓨터 구조 특론 교수님 : 이상정 교수님 팀 원 : 강명숙, 박장수.
CDA 3101 Spring 2016 Introduction to Computer Organization
SimpleScalar 설치 및 사용법 순천향대학교 정보기술공학부 이상정.
Assemblers, Linkers, and Loaders Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See: P&H Appendix B.3-4 and 2.12.
Instructor: Prof. Hany H Ammar, LCSEE, WVU
Simple Scalar 설치 및 사용법 일반대학원 전산학과 강서일 (2003 ) 손재락 ( )
MIPS Arithmetic is 32 bits
Spec2000 Optimization Level Result Report 순천향대학교.
Rocky K. C. Chang Version 0.1, 25 September 2017
Prof. Hsien-Hsin Sean Lee
순천향대학교 전산학과 SimpleScalar 예제 프로그램 순천향대학교 전산학과
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Topic 2e High-Level languages and Systems Software
Adventures in Assembly Land
MIPS coding.
Prof. Hakim Weatherspoon
Prof. Hakim Weatherspoon
Jeremy R. Johnson Wed. Apr. 5, 2000
ECE232: Hardware Organization and Design
MIPS coding.
Computer Organization and Design Assembly & Simulation
Компьютерийн зохион байгуулалт, ассемблер CS201
Computer Organization and Design Assembly & Compilation
CS334: Memory _ Mars simulator Lab 4(part2-2)
Flow of Control -- Conditional branch instructions
Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan
Systems Architecture I
Flow of Control -- Conditional branch instructions
Review.
Assemblers, Linkers, and Loaders
MIPS coding.
CS352H Computer Systems Architecture
10/6: Lecture Topics C Brainteaser More on Procedure Call
MIPS Assembly Language Programming
Compilers Jakub Yaghob
Program Assembly.
Assemblers, Linkers, and Loaders
Caches & Memory.
Presentation transcript:

1 간단한 C 프로그램 김희자, 최정욱

2 목차 예제 소스 코드 컴파일 어셈블리 언어 Dlite 디버거 수행

3 예제 소스 코드 #include int sum=0; main() { int i = 0; for(i=1; i<=5; i++) sum = sum + i; printf("%d\n", sum); }

4 컴파일 edu]sslittle-na-sstrix-gcc -o simplec.ss simplec.c edu]sslittle-na-sstrix-gcc -S simplec.c

5 어셈블리 언어 (1/4 ).file 1 "simplec.c" # GNU C [AL 1.1, MM 40, tma 0.1] SimpleScalar running sstrix compiled by GNU C # Cc1 defaults: # -mgas -mgpOPT # Cc1 arguments (-G value = 8, Cpu = default, ISA = 1): # -quiet -dumpbase -o gcc2_compiled.: __gnu_compiled_c:.globl sum.sdata.align 2 sum:.word 0.align 2

6 어셈블리 언어 (2/4 ) $LC0:.ascii "%d\n\000".text.align 2.globl main.text.loc 1 6.ent main main:.frame $fp,32,$31 # vars= 8, regs= 2/0, args= 16, extra= 0.mask 0xc ,-4.fmask 0x ,0 subu $sp,$sp,32

7 어셈블리 언어 (3/4 ) sw $31,28($sp) sw $fp,24($sp) move $fp,$sp jal __main sw $0,16($fp) li $2,0x # 1 sw $2,16($fp) $L2: lw $2,16($fp) slt $3,$2,6 bne $3,$0,$L5 j $L3 $L5: lw $2,sum lw $3,16($fp) addu $2,$2,$3 sw $2,sum

8 어셈블리 언어 (4/4 ) $L4: lw $3,16($fp) addu $2,$3,1 move $3,$2 sw $3,16($fp) j $L2 $L3: la $4,$LC0 lw $5,sum jal printf $L1: move $sp,$fp # sp not trusted here lw $31,28($sp) lw $fp,24($sp) addu $sp,$sp,32 j $31.end main

9 Dlite 디버거 수행 결과 (1/7) edu]# simplesim-3.0/sim-safe -i simplec.ss DLite! > dis main 0x004001f0: addiu r29,r29,-32 0x004001f8: sw r31,28(r29) 0x : sw r30,24(r29) 0x : addu r30,r0,r29 0x : jal 0x x : sw r0,16(r30) 0x : addiu r2,r0,1 0x : sw r2,16(r30) 0x : lw r2,16(r30) 0x : slti r3,r2,6 0x : bne r3,r0,0x x : j 0x x : lw r2,-32768(r28) 0x : lw r3,16(r30) 0x : addu r2,r2,r3 0x : sw r2,-32768(r28)

10 Dlite 디버거 수행 결과 (2/7) DLite! > break 0x breakpoint #1 class: exec DLite! > cont Stopping at code breakpoint 0x [ 198] 0x : addu r2,r2,r3 DLite! > iregs PC: 0x NPC: 0x HI: 0x LO: 0x FCC: 0x $r0: 0/0x $r1: 0/0x $r2: 0/0x $r3: 1/0x $r4: /0x100011c8 $r5: /0x7fff8004 $r6: /0x7fff800c $r7: /0x100011c0 $r8: /0x7efefeff $r9: /0x2f2f2f2f $r10: 0/0x $r11: 0/0x $r12: 0/0x $r13: 0/0x $r14: 0/0x $r15: 0/0x

11 Dlite 디버거 수행 결과 (3/7) $r16: 1/0x $r17: /0x7fff8004 $r18: /0x7fff800c $r19: 0/0x $r20: 0/0x $r21: 0/0x $r22: 0/0x $r23: 0/0x $r24: 0/0x $r25: 0/0x $r26: 0/0x $r27: 0/0x $r28: /0x $r29: /0x7fff7fc8 $r30: /0x7fff7fc8 $r31: /0x DLite! > cont Stopping at code breakpoint 0x [ 210] 0x : addu r2,r2,r3 DLite! > cont Stopping at code breakpoint 0x [ 222] 0x : addu r2,r2,r3 DLite! > cont Stopping at code breakpoint 0x [ 234] 0x : addu r2,r2,r3

12 Dlite 디버거 수행 결과 (4/7) DLite! > cont Stopping at code breakpoint 0x [ 246] 0x : addu r2,r2,r3 DLite! > iregs PC: 0x NPC: 0x HI: 0x LO: 0x FCC: 0x $r0: 0/0x $r1: 0/0x $r2: 10/0x a $r3: 5/0x $r4: /0x100011c8 $r5: /0x7fff8004 $r6: /0x7fff800c $r7: /0x100011c0 $r8: /0x7efefeff $r9: /0x2f2f2f2f $r10: 0/0x $r11: 0/0x $r12: 0/0x $r13: 0/0x

13 Dlite 디버거 수행 결과 (5/7) $r14: 0/0x $r15: 0/0x $r16: 1/0x $r17: /0x7fff8004 $r18: /0x7fff800c $r19: 0/0x $r20: 0/0x $r21: 0/0x $r22: 0/0x $r23: 0/0x $r24: 0/0x $r25: 0/0x $r26: 0/0x $r27: 0/0x $r28: /0x $r29: /0x7fff7fc8 $r30: /0x7fff7fc8 $r31: /0x DLite! > step [ 247] 0x : sw r2,-32768(r28) DLite! > cont 15

14 Dlite 디버거 수행 결과 (6/7) sim: ** simulation statistics ** sim_num_insn 7638 # total number of instructions executed sim_num_refs 4149 # total number of loads and stores executed sim_elapsed_time 119 # total simulation time in seconds sim_inst_rate # simulation speed (in insts/sec) ld_text_base 0x # program text (code) segment base ld_text_size # program text (code) size in bytes ld_data_base 0x # program initialized data segment base ld_data_size 8192 # program init'ed `.data' and uninit'ed `.bss' size in bytes ld_stack_base 0x7fffc000 # program stack segment base (highest address in stack)

15 Dlite 디버거 수행 결과 (7/7) ld_stack_size # program initial stack size ld_prog_entry 0x # program entry point (initial PC) ld_environ_base 0x7fff8000 # program environment base address address ld_target_big_endian 0 # target executable endian-ness, non-zero if big endian mem.page_count 26 # total number of pages allocated mem.page_mem 104k # total size of memory pages allocated mem.ptab_misses 26 # total first level page table misses mem.ptab_accesses # total page table accesses mem.ptab_miss_rate # first level page table miss rate