Yank me.
In-Game Name: -quit-
Current Level: -quit-
Server: Teva
Posts: 1,502
|
Hmm, the server went offline several times during the day. Just curious...
Besides, if you had to choose between assemply programming and surfing FF, the choice would be obvious. Here's some assemply coding to show you what I mean.
The main program:
Quote:
|
.globl Fraction
.globl getNumerator
.globl getDenominator
.globl adding
.globl setNumerator
.globl setDenominator
.text
Fraction:
#--------------------------------------------
add "$"t0, "$"0, "$"a0 # t0 = numerator
add "$"t1, "$"0, "$"a1 # t1 = denominator
x: addi "$"v0, "$"0, 9 # service #9 - specify num of bytes in "$"a0
addi "$"a0, "$"0, 8 # a0 = 8(block of bytes to be allocated in the heap)
syscall
sw "$"t0, 0("$"v0) # store t0 (num) at v0 (starting address)
sw "$"t1, 4("$"v0) # store t1 (denom) at 4 bytes down from v0 (starting address in mem)
jr "$"ra
# store the attributes somewhere in memory and
# return a reference to where they are
getNumerator:
#---------------------------------------------
lw "$"v0, 0("$"a0)
jr "$"ra
# retrieve the numerator of this
# fraction and return it in "$"v0
getDenominator:
#---------------------------------------------
lw "$"v0, 4("$"a0)
jr "$"ra
# retrieve the numerator of this
# fraction and return it in "$"v0
adding:
#---------------------------------------------
lw "$"t0, 0("$"a0) # numerator first fraction
lw "$"t1, 4("$"a0) # denominator first fraction
lw "$"t2, 0("$"a1) # numerator second fraction
lw "$"t3, 4("$"a1) # denominator second fraction
mult "$"t0, "$"t3
mflo "$"t0
mult "$"t1, "$"t2
mflo "$"t2
add "$"t0, "$"t0, "$"t2
mult "$"t1, "$"t3
mflo "$"t1
j x
setNumerator:
#---------------------------------------------
add "$"t0, "$"0, "$"a0 # t0 = numerator
sw "$"t0, 0("$"v0) # store t0 (num) at v0 (starting address)
jr "$"ra
#---------------------------------------------
setDenominator:
#---------------------------------------------
add "$"t1, "$"0, "$"a1 # t0 = numerator
sw "$"t1, 4("$"v0) # store t0 (num) at 4 bytes down v0 (starting address)
jr "$"ra
#---------------------------------------------
|
And the client:
Quote:
|
.text
#-----------------------------------------------
main: sw "$"ra, 0("$"sp) # store ra(return address) in sp(Stack Pointer)
addi "$"sp, "$"sp, -4 # decrement stack pointer by 4 bytes
addi "$"a0, "$"0, 3 # a0 = 3 (argument0)
addi "$"a1, "$"0, 8 # a1 = 8 (argument1)
jal Fraction # jump and link to Fraction
add "$"s0, "$"0, "$"v0 # s0 holds address stored in v0 (3/8)
addi "$"a0, "$"0, 1 # a0 = 1 (argument0)
addi "$"a1, "$"0, 2 # a1 = 2 (argument1)
jal Fraction
add "$"s1, "$"0, "$"v0 # s1 holds address stored in v0 (1/2)
add "$"a0, "$"0, "$"s0
add "$"a1, "$"0, "$"s1
jal adding
add "$"s2, "$"0, "$"v0
#-----------------
add "$"a0, "$"0, "$"s0
jal getNumerator
add "$"a0, "$"0, "$"v0 # store the numerator from v0 in "$"a0 (temp)
addi "$"v0, "$"0, 1
syscall
addi "$"v0, "$"0, 11
addi "$"a0, "$"0, '/'
syscall
add "$"a0, "$"0, "$"s0
jal getDenominator
add "$"a0, "$"0, "$"v0
addi "$"v0, "$"0, 1
syscall
#------------------
addi "$"v0, "$"0, 11
addi "$"a0, "$"0, 10
syscall
#------------------
add "$"a0, "$"0, "$"s1
jal getNumerator
add "$"a0, "$"0, "$"v0 # store the numerator from v0 in "$"a0 (temp)
addi "$"v0, "$"0, 1
syscall
addi "$"v0, "$"0, 11
addi "$"a0, "$"0, '/'
syscall
add "$"a0, "$"0, "$"s1
jal getDenominator
add "$"a0, "$"0, "$"v0
addi "$"v0, "$"0, 1
syscall
#------------------
addi "$"v0, "$"0, 11
addi "$"a0, "$"0, 10
syscall
#------------------
add "$"a0, "$"0, "$"s2
jal getNumerator
add "$"a0, "$"0, "$"v0 # store the numerator from v0 in "$"a0 (temp)
addi "$"v0, "$"0, 1
syscall
addi "$"v0, "$"0, 11
addi "$"a0, "$"0, '/'
syscall
add "$"a0, "$"0, "$"s2
jal getDenominator
add "$"a0, "$"0, "$"v0
addi "$"v0, "$"0, 1
syscall
#------------------
add "$"v0, "$"0, "$"s1
addi "$"a0, "$"0, 7 # a0 = 7 (argument0)
addi "$"a1, "$"0, 9 # a1 = 9 (argument1)
jal setNumerator
jal setDenominator
#------------------
addi "$"v0, "$"0, 11
addi "$"a0, "$"0, 10
syscall
#------------------
add "$"a0, "$"0, "$"s1
jal getNumerator
add "$"a0, "$"0, "$"v0 # store the numerator from v0 in "$"a0 (temp)
addi "$"v0, "$"0, 1
syscall
addi "$"v0, "$"0, 11
addi "$"a0, "$"0, '/'
syscall
add "$"a0, "$"0, "$"s1
jal getDenominator
add "$"a0, "$"0, "$"v0
addi "$"v0, "$"0, 1
syscall
#------------------
addi "$"sp, "$"sp, 4
lw "$"ra, 0("$"sp)
jr "$"ra
|
All this does is print:
3/8
1/2
14/16
7/9
....No really.
EDIT: Had to to put "" around dollar signs, otherwise variables wouldn't parse properly.
Last edited by Belaslav; 02-08-2011 at 08:43 PM..
|