DOC PREVIEW
UW CSE 378 - Machine Organization and Assembly Language Programming

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 378 Spring 2003Machine Organization and Assembly Language ProgrammingProblem Set #5Due: Friday May 9thIn this assignment you’ll use the Smok tool to put together a single cycle implementation of the MIPSdatapath. This is a prelude to the pipeline implementation so you might want to keep this in mindwhen defining components/containers.You can work in teams of two if you so desire.The machine you build should be able to calculate the factorial of a given number, i.e., you need toimplement the following instructions (maybe not all of the arithmetic ones are needed but it won’t beextra work to do it!):• Arithmetic: ADD, ADDU, SUB, SUBU, MUL (Note that the MUL given by the Smok tool isdifferent from the one given by the MIPS implementation. Follow the easy route, i.e., the Smokone. Also, Smok’s ALU has different opcodes than those given by the function bits of the MIPSopcode. It is quite OK to, again, follow the easy route i.e., follow the Smok ALU convention).• Immediate instructions: ADDI and anything you need to implement LI, e.g., ORI.• Load Store instructions: LW and SW.• Transfer of control: JAL, JR, BEQ, BNE.The code for factorial is given in MIPS assembly language on a following page (it computes 5! but wemight want to test your program on different values). The binary, i.e., the .smokmem file is also on afollowing page. (If you look at the .html version of this assignment, you’ll find the links to downloadthe programs.) Note that while MIPS programs start with a PC of 0x04000000, the Smok tool expectsa beginning PC of 0x00000000.Your 32 registers and the PC should be like MIPS’s, i.e., 32-bit long. However, we are going to restrictthe amount of memory to 1024 Bytes, i.e., 256 words. This explains the beginning of the main programcalling the factorial function, i.e., the top of the stack is now at address 1024 (minus 4) and will growtoward address 0.If you need static and dynamic data, you should start storing them at the 512 byte (128 word) boundary.In order for us to test your implementation more easily, you should include a “halt” component thatwill be triggered when the self-loop of the main program is reached.A few Smok-MIPS quirks.• Beware that SPIM (in the default configuration) doesn’t calculate branch offsets from PC+4 (itcalculates them from PC), and that jump addresses will be different if you assemble the programwith SPIM. The .smokmem file uses a displacement from PC+4, compatible with the real MIPSimplementation.• In the single cycle implementation of MIPS, there are separate memories for instruction and data.In Smok you can use the same memory with different interfaces: an IF for instruction fetch and aregular Memory Interface for the data memory. Whether you use 1 or 2 memories is your choice.• Although Smok provides limited I/O capabilities through direct mapped I/O controllers, you arenot asked to implement this. It would require the use of library routines, syscalls, and moregenerally the Cebollita system (you are welcomed to try it for extra credit). At the end of thecomputation, your result should be in register $v0.• When you reinitialize the Smok machine, all registers are reset to 0. Whether you want tohardwire register 0 to zero is your choice.• Testing your machine. It might be useful to test each instruction type one at a time (e.g., builda one instruction .smokmem file).What you have to turnin.• a README file indicating briefly how to “operate” your machine in case it is not obvious, i.e.,which files to load etc.. In case you are aware of bugs and did not have time to correct them,indicate it in the README file.• a .smok file for your implementation (and any .smokcont for containers), a .smokpla file for thePLA, a .smokmem for the memory.• More specifically, send e-mail to Tapan (tapan@cs) with subject 378ASS5, including files LAST-NAME.README, LASTNAME.smok, LASTNAME.smokmem, and LASTNAME.smokpla. AlsoLASTNAME-ComponentType.smokcont for any required containers.One turnin per set of partners is enough but be sure to indicate both names in the README file.main: # Will start at PC 0x00000000## Main program entry#addi $sp,$0,1024 #the stack will start at (byte) addressaddi $sp,$sp,-4 #1024 and grow downwardsli $a0, 5 #will compute factorial of 5jal factaddi $sp,$sp,4 #restores the stackbeq $0,$0,-1 # a "halt" instruction# PROCEDURE: Fact# PARAMETERS: an integer in a0# LOCALS:# RETURN: fact(a0) in v0# DESCRIPTION: Computes recursively factorial#fact: sw $ra,0($sp) #save return addressaddi $sp,$sp,-4 #move sp to new position in frame## Procedure body## test argument for 0 ; if so return with value 1beq $a0,$0,nore #test a0 ; if zero go to out# otherwise save a0 on the stacksw $a0,0($sp) #push argument on stackaddi $sp,$sp,-4addi $a0,$a0,-1 #decrement argument##recursive entry#jal fact #call##back from recursive level v0 =v 0 * ao#addu $sp,$sp,4lw $t0,0($sp) #pop argument from stackmul $v0,$v0,$t0 #get result at this levelb out #exit that level##end of recursion#nore: li $v0,1 #result in v0 and exit## Procedure exit#out: addi $sp,$sp,4lw $ra,0($sp) #restore return addressjr $ra #returnThe .smokmem


View Full Document

UW CSE 378 - Machine Organization and Assembly Language Programming

Documents in this Course
Encoding

Encoding

20 pages

Load more
Download Machine Organization and Assembly Language Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Machine Organization and Assembly Language Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Machine Organization and Assembly Language Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?