MIPS assembly for a simple for loop

后端 未结 4 1354
长发绾君心
长发绾君心 2021-02-09 00:24

I need to translate this C code to MIPS assembly. Here is the C code:

int tmp = 0; 
for (int  j = 0; j < 15; ++j) 
     tmp = tmp * 2 + 3

Th

4条回答
  •  孤城傲影
    2021-02-09 01:11

    .data
    mensage: asciiz "Text Test"
    newline: asciiz "\n"
    .text
    
    # tmp = $v0
    # j = $t0
     
    main:
        li $t0,0
        li $t1,0
        li $t3,0
    loop:
        bgt $t0,15,exit
        addi $t0,$t0,1
        j loop
        mul $t1,$t1,2
        add $t3,$t1,3  
    exit:
        li $v10,0
        syscall
    

提交回复
热议问题