Jump to content

program not compiling/running

- - - - -

  • Please log in to reply
3 replies to this topic

#1
shopnobhumi

shopnobhumi

    Newbie

  • Members
  • Pip
  • 1 posts
.txt
.globl main

main:
# f= (g+h)-(i+j);

li $s0,0
li $t1,0
li $t2,0
li $s1,4
li $s2,5
li $s3,6
li $s4,7

add $t1, $s1, $s2 # sum of s1,s2 is stored in t1 or temporary variable
t1 contains g+h

add $t2, $s3, $s4 # sum of s3,s4 is stored in t2 or temporary variable
t2 contains i+j

sub $s0, $t1, $t2 # s0 gets $t1- $t2, which is (g+h)-(i+j)
li $v0, 1
move $a0, $s0
syscall
li $v0, 10
syscall

#2
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
Um, what architecture? What assembler?
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#3
Guest_h4x_*

Guest_h4x_*
  • Guests
since there is syscall instruction, it must be ia-32e or itanium.
i belive that li/move are not instructions, but some ****ty macroes.

i bet its a ia-32e + some really uncommon assembler.

#4
TkTech

TkTech

    The Crazy One

  • Moderators
  • 1,396 posts
h4x: Your stupidity once again amazes me.

Alright, first off, lets finish your homework shopnubhumi. Your snippet is for a MIPS machine.
I take it, from the quality of your work you are new to it, so, I'll take it easy.


# Example program for shopnobhum

# f = (g+h) - (i+j)

##

# $t0 - current total

# $t1 - i+j


main:

    li $t0, 4           # (Load Immediate) 4 (g) into $t0

    addi $t0, $t0, 5    # (Add Immediate) $t0 (4) + 5 (h) into $t0


    li $t1, 6           # (Load Immediate) 6 (i) into $t1

    addi $t1, $t1, 7    # (Add Immediate) $t1 (6) + 7 (j) into $t1


    sub $t0, $t1, $t0   # (Subtract Register) $t1 from $t0 into $t0


    move $a0, $t0       # (Move Register) $t0 into $a0

    li $v0, 1           # (Load Immediate) 1 (Print Integer) into $v0

    syscall             # System Call


    li $v0, 10          # (Load Immediate) 10 (Exit) into $v0

    syscall             # System Call


That should work on most MIPS emulators/machines.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users