News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

IF-OR-THEN-ELSE construction

Started by Herakles, May 02, 2010, 02:09:19 PM

Previous topic - Next topic

clive

Going back to your original attempt, it might very well be more efficient to lose the branch and drop through

then: sub $t0, $t0, 9 # THEN $t0 := $t0 - 10 (-9 followed by -1)
else: sub $t0, $t0, 1 # ELSE $t0 := $t0 - 1

It could be a random act of randomness. Those happen a lot as well.

Slugsnack

Quote from: clive on May 03, 2010, 05:46:47 PM
Going back to your original attempt, it might very well be more efficient to lose the branch and drop through

then: sub $t0, $t0, 9 # THEN $t0 := $t0 - 10 (-9 followed by -1)
else: sub $t0, $t0, 1 # ELSE $t0 := $t0 - 1


I thought of this but figured because of the dependency, the data hazard would stall the pipeline and cause a bubble so didn't bother suggesting it.

clive

Would be a problem in implementations without register forwarding. Adding a NOPs would still be cheaper than a branch with an empty slot.

Something along the lines of this might also be viable, but assumes negative numbers are larger than 100 in unsigned space.

sltu $t2,$t0,100  ; MIPS IV
addiu $t1,$t0,-10
addiu $t0,$t0,-1
        nop
movz $t0,$t1,$t2
It could be a random act of randomness. Those happen a lot as well.

Herakles

Here is the result, as promised:
No mistakes, full points.

Thank you so much for your help! :U

For us, SPIM is part of "computer architecture" and it makes up only about 25% of the course.

We have to do another exercise and I'll post it later on, since it seems to be difficult (sth. like write a programme, that reads in a string and changes the small letters to capital ones).

brethren

Quote from: Herakles on May 17, 2010, 02:29:41 PM

We have to do another exercise and I'll post it later on, since it seems to be difficult (sth. like write a programme, that reads in a string and changes the small letters to capital ones).

changing from uppercase to lowercase and vice-versa is a very simple exercise (assuming you're using the ascii charset)

A = 01000001
a = 01100001

as you can see changing between upper/lowercase is just a case of toggling a single bit

Herakles

Quote from: brethren on May 17, 2010, 03:22:05 PMchanging from uppercase to lowercase and vice-versa is a very simple exercise (assuming you're using the ascii charset)

A = 01000001
a = 01100001

as you can see changing between upper/lowercase is just a case of toggling a single bit

I have to make myself familiar with the new aspects so I'll hopefully be able to write a working programme.

I've started a new thread containing the current exercise.