$s2 = j
$s3 = k
$a0 = base address of array a[]
C
code
if(j<k) a[j] = 1;
else j = a[j];
MIPS
Code
slli $t2, $s2, 2 //$t2 = 4*j
add $t2, $t2, $a0 //$t2 = &a[j]
slt $t1, $s2, $s3 //if(j<k) set $t1 =
1
beq $t1, $zero, Else //if($t1 = 0) branch
to Else
addi $t1, $zero, 1 //$t1 = 1
sw $t1, 0($t2) //a[j] =
1
j Exit
//jump to Exit
Else:
lw $s2, 0($t2) //j =
a[j]
Exit:
For C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. No credit for pseudo-MIPS instructions (e.g., BGE). The answer MUST use true 32-bit MIPS instructions: if(j < k ) a[j] = 1; else j = a[j];
C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: if(j < k ) a[j] = 1; else j = a[j];
For C to MIPS Conversion C variable h i j k X int a[] or &a[0] MIPS register replac ement $50 $51 $s2 $s3 $54 $a0 Translate to MIPS. No credit for pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: Note that all variables (h,i,j,x,a[]) are 32-bit signed integers. while ( h < 3 ) { a[j++] = 0; x = i >> 3; }
For C to MIPS Conversion C variable h i j k int a[] or &a[0] MIPS register replacement $50 $s1 $s2 $53 $54 $a0 Translate to MIPS. No credit for pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: Note that all variables (h,ij.x,a[]) are 32-bit signed integers. while ( h < 3 ) { a[j++] = 0; x = i >> 3; ܒܝܢ
C to MIPS Conversion C variable h i j k x int a[] or &a[0] MIPS register replacement $s0 $s1 $s2 $s3 $s4 $a0 Translate to MIPS. DO NOT USE pseudo MIPS instructions (e.g., BGE). Answer MUST use true 32-bit MIPS instructions: Note that all variables (h,i,j,x,a[]) are 32-bit signed integers. while ( h < 3 ) { a[j++]= 0; x = i >> 3; }
Translate each of the following pseudo-instructions into MIPS instructions. You should Produce a minimal sequence of MIPS instructions to accomplish the required computation. (8 Points) 1) bgt $t1, 100, Label # bgt means branch if greater than 2) ble $s2, 10, Next # ble means branch if less than or equal 3) ror $s0, $s4, 7 # ror means rotate right $s4 by 7 bits and store the result in $s0 4) neg $s5, $s4 # $s5 will have the...
translate c++ to mips bool singleton(int value) { //Check condition if (value == 0) //Return return false; //Declare and initialize int compare = value-1; bool isTrue = value & compare; //Check condition if (isTrue == 0) //Return return true; //Otherwise else //Return return false; }
2.29 The following is the C codes and the translated MIPS codes. Assume that the C-level integers t1 and a0 are held in register $t1 and $a0, and $s0 holds the base address of the integer MemArray. void foo () { int MemArray[100] = { 96, 98, 63, 69, 42, 27, 16, 6, 47, 74, 44, 33, 76, 7, 88, 33, 80, 86, 86, 64, 17, 67, 60, 51, 2, 61, 93, 87, 49, 98, 24, 98, 30, 65, 2,...
05/0172019 Q1: (20) Choose one of these C code fragments and write it in PIC24 assembly form. if (u16 i< u16 k) |I True if((u 16-i <ul6k) && TAR (ul6j_u16_p)11 (16.9 !=0)) { if body Falttau 16-j != 80)) { if body else else else-body else-body f code rest of code s else.
05/0172019 Q1: (20) Choose one of these C code fragments and write it in PIC24 assembly form. if (u16 i
27. For lO computer interface function outb(0xB6, 0x43), which register to hold Ox43? (a) AL (c) DX (d) AX (b) BL 28. Suppose memory variable j is 32-bit. After executing the following instructions int j 0X20AB int *Ptr asmi MOV EAX, Ptr; MOV EBX, [EAX] ADD EBX, 1; Which of the following statements is true? (b) EBX hold 0x20AC in hexadecimal (d) EAX hold 0x20AC in hexadecimal (a) EBX hold 0x20AB in hexadecimal (c) EAX hold Ox20AB in hexadecimal 29....