2
LABORATORY LEARNING OBJECTIVES Explore the core MIPS instruc0on set. Write MIPS assembly language programs Use MIPS simulators. LABORATORY REQUIREMENTS 1. Work these exercises alone. 2. Consult the instructor and classmates for help if needed. 3. Use the MARS simulator. 4. Use simulator system calls to get data from the user and return results to the user. 5. Use argument registers $a0$a3 to pass values to subrou0nes. 6. Use value register $v0 to return values from subrou0nes. 7. Use temporary registers for intermediate calcula0ons. 8. Use saved registers only for variables retrieved from the user. 9. Use only the core instruc0on set from the leKhand column of page 1 of the MIPS green card. Do not use any mul0ply and divide instruc0ons from page 2 of the green card. 10. Use the la and li pseudoinstruc0ons only with the syscall OS service to complete user I/O. Consult the informa0on on the last page of this handout for details about OS syscalls. 11. Do not use any other MIPS assembly language pseudoinstruc0ons. 12. Explain your work with appropriate MIPS assembly line comments (#). 13. Demonstrate each program to the instructor when you have finished the en0re lab. Demos may be completed at the start of the next lab period or during office hours. Come to lab prepared to demo. 14. Submit a formal laboratory report at the 0me of your demonstra0on. Include problem statements, source code, and simula0on screenshots linked with text that describes your algorithmic solu0on to each programming task. Include the soKware blueprints, such as flowcharts or UML sequence diagrams, that you created before wri0ng each program. Email your report in PDF format to the instructor. PRELIMINARY LABORATORY READING There are a number of high quality integrated development environments for the MIPS architecture. Most include syntax highligh0ng, debugging tools, and simula0on. The MARS integrated development environment is very good; it is the recommended environment in CE2930. Consult the extensive help panel available in MARS for informa0on about using MARS, the MIPS instruc0on set, and the simulated OS system calls available for user input and output. CE2930 WEEK 1 LABORATORY EXERCISES Computer Engineers: We Put Computers in Stuff! Spring 2014 Page 1/2 These homework and laboratory exercises are © Dr. Russ Meier, Milwaukee School of Engineering. All Rights Reserved. Unauthorized reproducZon in print or electronic form is prohibited.

lw1

Embed Size (px)

DESCRIPTION

MIPS

Citation preview

Page 1: lw1

LABORATORY  LEARNING  OBJECTIVES

• Explore  the  core  MIPS  instruc0on  set.• Write  MIPS  assembly  language  programs• Use  MIPS  simulators.

LABORATORY  REQUIREMENTS

1. Work  these  exercises  alone.    2. Consult  the  instructor  and  classmates  for  help  if  needed.      3. Use  the  MARS  simulator.    4. Use  simulator  system  calls  to  get  data  from  the  user  and  return  results  to  the  user.  5. Use  argument  registers  $a0-­‐$a3  to  pass  values  to  subrou0nes.6. Use  value  register  $v0  to  return  values  from  subrou0nes.7. Use  temporary  registers  for  intermediate  calcula0ons.  8. Use  saved  registers  only  for  variables  retrieved  from  the  user.      9. Use  only  the  core  instruc0on  set  from  the  leK-­‐hand  column  of  page  1  of  the  MIPS  green  

card.  Do  not  use  any  mul0ply  and  divide  instruc0ons  from  page  2  of  the  green  card.    10. Use  the  la  and  li  pseudo-­‐instruc0ons  only  with  the  syscall  OS  service  to  complete  user  I/O.    

Consult  the  informa0on  on  the  last  page  of  this  handout  for  details  about  OS  syscalls.11. Do  not  use  any  other  MIPS  assembly  language  pseudo-­‐instruc0ons.12. Explain  your  work  with  appropriate  MIPS  assembly  line  comments  (#).  13. Demonstrate  each  program  to  the  instructor  when  you  have  finished  the  en0re  lab.  Demos  

may  be  completed  at  the  start  of  the  next  lab  period  or  during  office  hours.  Come  to  lab  prepared  to  demo.  

14. Submit  a  formal  laboratory  report  at  the  0me  of  your  demonstra0on.  Include  problem  statements,  source  code,  and  simula0on  screenshots  linked  with  text  that  describes  your  algorithmic  solu0on  to  each  programming  task.  Include  the  soKware  blueprints,  such  as  flowcharts  or  UML  sequence  diagrams,  that  you  created  before  wri0ng  each  program.  Email  your  report  in  PDF  format  to  the  instructor.    

PRELIMINARY  LABORATORY  READING

There  are  a  number  of  high  quality  integrated  development  environments  for  the  MIPS  architecture.  Most  include  syntax  highligh0ng,  debugging  tools,  and  simula0on.  The  MARS  integrated  development  environment  is  very  good;  it  is  the  recommended  environment  in  CE2930.  Consult  the  extensive  help  panel  available  in  MARS  for  informa0on  about  using  MARS,  the  MIPS  instruc0on  set,  and  the  simulated  OS  system  calls  available  for  user  input  and  output.  

CE2930  WEEK  1  LABORATORY  EXERCISES                    

Computer  Engineers:    We  Put  Computers  in  Stuff!                    Spring  2014   Page  1/2

These  homework  and  laboratory  exercises  are  ©  Dr.  Russ  Meier,  Milwaukee  School  of  Engineering.All  Rights  Reserved.    Unauthorized  reproducZon  in  print  or  electronic  form  is  prohibited.

Page 2: lw1

LABORATORY  EXERCISES

1. Write  a  MIPS  assembly  language  program  that  gets  an  integer,  i,  from  the  user.    For  all  X  in  the  integer  set  from  i  downto  1:    write  the  approximate  area  and  approximate  volume  of  a  sphere  with  radius  X  to  the  screen  with  an  informa0ve  user  message  string.  Approximate  the  area  and  volume  using  integer  mathema0cs  with  π  =  3.  Note  that  you  are  not  allowed  to  use  mul0ply  and  divide  instruc0ons.  Thus,  you  must  use  addi0on  or  subtrac0on.    SubrouZnes  are  not  required  but  may  make  the  task  more  modular.    

2. Write  a  MIPS  assembly  language  program  that  gets  two  integers,  i  and  j,  from  the  user  and  finds  all  mul0ples-­‐of-­‐4  between  the  two  numbers.  SubrouZnes  are  not  required  but  may  make  the  task  more  modular.  An  example  table  is  shown  below.

User  inputs Outputi  =  3,  j  =  4 Nonei  =  3,  j  =  12 Mul0ples-­‐of-­‐4  are:    4  i  =  3,  j  =  20 Mul0ples-­‐of-­‐4  are:    4,  8,  12,  16i  =  0,  j  =  15 Mul0ples-­‐of-­‐4  are:    0,  4,  8,  12i  =  10,  j  =  2 Input  i  is  not  less  than  input  j

3. Write  a  MIPS  assembly  language  program  that  gets  an  integer  i  from  the  user  and  creates  the  table  shown  below  on  the  screen  (example  inputs  provided).    SubrouZnes  are  required  for  power,  square,  and  hexadecimal.  Write  the  subrou0nes  for  32-­‐bit  arithme0c.  It  is  understood  that  some  user  inputs  will  produce  overflowed  results.  Hint:  hexadecimal  can  be  done  with  shiKs  and  masks  because  you  know  the  size  is  32  bits.  This  would  be  more  difficult  if  the  size  was  variable.    Also,  consult  the  help  facility.  There  might  be  a  print  hexadecimal  as  a  system  call.  

User  Input  i power(2,i) square(i) Hexadecimal(i)10 1024 100 0xA7 128 49 0x716 65536 256 0x1013 8192 169 0xD

CE2930  WEEK  1  LABORATORY  EXERCISES                    

Computer  Engineers:    We  Put  Computers  in  Stuff!                    Spring  2014   Page  2/2

These  homework  and  laboratory  exercises  are  ©  Dr.  Russ  Meier,  Milwaukee  School  of  Engineering.All  Rights  Reserved.    Unauthorized  reproducZon  in  print  or  electronic  form  is  prohibited.