Results 1 to 3 of 3

Thread: Could someone please explain to me what this MIPS code does?

  1. #1
    Join Date
    Mar 2007
    Beans
    1,016

    Could someone please explain to me what this MIPS code does?

    Hello everyone.

    Could someone please explain to me what the following MIPS code does?:
    Code:
    .text
    .globl main
    
    main:
    	li $11,15
    	li $10,32
    	li $6,0
    main10:
    	andi $12, $11, 1
    	beq $12, $0, main20
    	addi $6, $6, 1
    main20:
    	srl $11, $11, 1
    	addi $10, $10, -1
    	bne $10, $0, main10
    	li $2,1
    	move $4,$6
    	syscall
    	li $2,10
    	syscall
    If more information is needed from me, ask me and I will give it to you.

    Any input would be greatly appreciated!

    Edit:
    I'm mostly concerned with:
    Code:
    .text
    .globl main
    and:

    Code:
    syscall
    .

    Edit #2:
    Also, what is the "goal" of this code?
    Last edited by s3a; March 24th, 2013 at 03:00 PM.
    Apps for Ubuntu (outdated) ---> http://cid-23a283fc1010a1bb.skydrive...%20Wine|6?uc=1
    Use Mnemosyne to Study for School!

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Could someone please explain to me what this MIPS code does?

    This looks a lot like a homework.

    Anyway, I'd rewrite the code like this to be slightly more readable:
    Code:
    .text
    .globl main
    
    main:
            li $t3,15
            li $t2,32
            li $a2,0
    main10:
            andi $t4,$t3,1
            beq $t4,zero, main20
            addi $a2,$a2,1
    main20:
            srl $t3,$t3,1
            addi $t2,$t2,-1
            bne $t2,zero, main10
            li $v0,1
            move $a0,$a2
            syscall
            li $a0,10
            syscall
    According to this page, syscall with $v0 set to 1 means print integer in $a0
    Last edited by schragge; March 24th, 2013 at 05:09 PM.

  3. #3
    Join Date
    May 2010
    Location
    Tewkesbury uk
    Beans
    7,882
    Distro
    Ubuntu Development Release

    Re: Could someone please explain to me what this MIPS code does?

    This looks like homework.
    Agreed. I think schragge is correct.

    Please do not post homework questions here unless you have had a demonstrable, good attempt at doing it yourself.
    Last edited by matt_symes; March 24th, 2013 at 05:09 PM.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •