1 / 13

COMS 361 Computer Organization

COMS 361 Computer Organization. Title: Instructions Date: 9/30/2004 Lecture Number: 11. Announcements. Homework 4 Due 10/05/04. Review. SPIM MIPS simulator SPIM program (exit.s) Comments Assembler directives .text .data Labels Instructions Data MIPS DataPath

kaya
Télécharger la présentation

COMS 361 Computer Organization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMS 361Computer Organization Title: Instructions Date: 9/30/2004 Lecture Number: 11

  2. Announcements • Homework 4 • Due 10/05/04

  3. Review • SPIM • MIPS simulator • SPIM program (exit.s) • Comments • Assembler directives • .text • .data • Labels • Instructions • Data • MIPS DataPath • Pseudo Instructions

  4. Outline • SPIM • MIPS simulator • Assembler directives

  5. Allocate space in the data segment of the SPIM memory model Allocates 4096 bytes in the data segment Assembler Directives • Used to create data structures that are available at run-time • To allocate a one-dimensional array in C++ int ARRAY[1024]; • Corresponds to the MIPS assemble directive .data ARRAY: .space 4096

  6. Assembler Directives • Allocate and initialize a one-dimensional array int ARRAY[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 }; • Corresponds to the MIPS assemble directive .data ARRAY: .word 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 la $a0 ARRAY # $a0 = &ARRAY[0] lw $s0 8($a0) # $s0 = MEM[2] $a0 contains a pointer to the array

  7. Assembler Directives • String literal definition .data helloStr: .ascii “Hello, World!\n” • helloStr is the memory location of the array of characters • The string is not null terminated • Can cause problems (hell01.s) .data helloStr: .asciiz “Hello, World!\n”

  8. Pseudo Instructions • Give the illusion of a richer instruction set • Translated into one or more “real” MIPS instructions la $a0 label • The problem in implementing this instruction is that label should be a 32-bit address • It will not fit into a single instruction lui $a0 upper 16-bits of label ori $a0 lower 16-bits of label

  9. Control Flow • MIPS conditional branch instructions bne $t0, $t1, Label beq $t0, $t1, Label • Example • C/C++ code: if(i==j) { h=i+j; } • MIPS code: bne $s0, $s1, Label add $s3, $s0, $s1 Label: .... • Implemented using reverse logic • Turned the equality condition around

  10. Control Flow if(i != j) { h = i + j; }else { h = i - j; } beq $s4, $s5, Lab1 add $s3, $s4, $s5 j Lab2 Lab1: sub $s3,$s4,$s5 Lab2: … Turned the test around Branched over the then part

  11. Control Flow • beq, bne are useful • What about branch-if-less-than? • New instruction if($s1 < $s2) $t0 = 1; else $t0 = 0; • Vanilla MIPS does not provide a ble instruction • It can be synthesized from other MIPS instructions

  12. Control Flow • The ble pseudo-instruction is implemented as two “real” MIPS instructions • slt $at, $s1, $s2 (set $t0 to 1 if $s1 < $s2) • beq $at, $0, Target if ($t0 == $0) goto Target0 • The assembler needs an extra register to convert this pseudo instruction into a sequence of actual MIPS instructions • $at can NOT contain a currently needed value

  13. Example • Implement the following while loop in MIPS assembly language • Assume an array save has 10 elements and they are filled with integer values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 int j = 0, sum = 0; int save[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; while (j < 10) { sum += save[j++]); } cout << “save array sum: “ << sum << endl;

More Related