3 questions on computer science

profileRico the expert
assignment2_f16.pdf

CS  2430  –  Assignment  2   Due:  Saturday  Oct  8th,  11:59  pm  on  Blackboard   Points:  30   Prof.  Lei     For  problems  1-­‐8,  assume  that  before  each  set  of  instructions,  $t0  =  0xFFFFFFFF,  $t1  =   0x00000000,  $t2  =  0x00000001.    Determine  the  value  of  $a0  in  32-­‐bit  Hexadecimal  after   each  set  of  instructions.     1)     add   $t3,$t2,$t1     add   $t3,$t3,$t0     or   $a0,$t3,$0     2)     slt   $a0,$t1,$t2     add   $a0,$a0,$t0     3)     and   $t3,$t0,$t2     xor   $t3,$t3,$t2     move   $a0,$t3     4)   add   $t3,$t0,$t0     add   $t3,$t3,$t0     add   $a0,$t3,$t0     5)     bgez   $t2,else     addi   $a0,$0,1     b   next   else:     addi   $a0,$0,0   next:     6)     bltz   $t2,else     addi   $a0,$0,1     b   next   else:     addi   $a0,$0,0   next:     7)     addi   $t3,$0,10     addi   $a0,$0,0   loop:       add   $a0,$a0,$t3     addi   $t3,$t3,-­‐1     bgtz   $t3,loop     8)     addi   $t3,$0,10     b   while   loop:     addi   $a0,$a0,1     addi   $t3,$t3,-­‐1   while:     bgez   $t3,loop  

CS  2430  –  Assignment  2   Due:  Saturday  Oct  8th,  11:59  pm  on  Blackboard   Points:  30   Prof.  Lei     For  problems  9-­‐25,  express  the  following  pseudo-­‐code  expressions  in  assembly  language,   using  as  few  clock  cycles  as  possible.  Declare  any  necessary  assembler  directives.  Assume   that  the  variable  names  correspond  to  MIPS  registers  (i.e.  the  variable  t0  corresponds  to   register  $t0).     9)    s0  =  s1  +  s2  +  s3     10)    t0  =  (t1  &  1)  |  0xFFFF     11)    t3  =  t2  –  t1  –  5     12)    while  (t0  >  0)  {  t1  =  t1  +  t2;    t0  =  t0  –  1}     13)    if  (t1  >  0)  {s0  =  1}  else  {s0  =  -­‐1}     14)    printf(“I  want  to  print  this  string\n”)     15)    s2  =  9  *  s1     16)    s3  =  (int)  s4  /  16       17)  for  (t0  =  0;  t0  <  10;  t0=t0+1)  {  t1  =  t1  +  t0  }     18)  s2  =  *(s1  +  2)           #  Note:  the  *  is  a  pointer  dereference     19)  *(s1  +  3)  =  s2     20)  a0  =  &array                 #  Note:  array  is  an  assembler  directive  of    

#  integer  type,  with  values  1,  2,  3,  and  4     21)  do  {  t0  =  t0  +  t1;  t1  =  t1  –  1;  }  while  (t1  >  0)     22)  for  (t2  =  10;  t2  >=  0;  t2=t2-­‐2  )  {  t1  =  t1  +  t2*2;  }     23)  if  (  t1  <  5  )  {  t0  =  1;  }  else  {  t0  =  0;  }     24)  t2  =  s3/16  +  32*s1  +  10     25)  s2  =  -­‐1  *  s1         26)    Write  a  MIPS  assembly  program  that  computes  the  sum  of  integers  N  to  1000,  where  N   is  input  by  the  user.  The  program  must  check  to  ensure  that  N  lies  between  0  through  1000.   Run  your  program  using  MIPSym2.0  and  make  sure  that  the  program  compiles  and   functions  correctly.    (You  will  be  graded  based  on  how  well  your  program  compiles  and  runs   on  MIPSym2.0)