User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 391,666 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,868 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser:
Views: 401 | Replies: 0
Reply
Join Date: May 2008
Posts: 1
Reputation: serendipity. is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
serendipity. serendipity. is offline Offline
Newbie Poster

Assembly floating point

  #1  
May 23rd, 2008
Hey there!

I had to write a programme for MIPS/SPIM, which reads floating point numbers and returns them bit by bit at the shell. So this is, what I managed to write:

.data
var1:		.float 		0.00
var2:		.float 		2.0
var3:		.float 		-0.123
txt2:		.asciiz		"\n"

.text

main:
addi	$sp, $sp, -20		# decrement stack pointer
l.s	$f0, var3		# load var3 in $f0
s.s	$f0, 20($sp)		# push $f0 on stack
addi	$sp, $sp, -20		# decrement stack pointer
l.s	$f1, var2		# load var2 in $f1
s.s	$f1, 20($sp)		# push $f1 on stack
addi	$sp, $sp, -20		# decrement stack pointer
l.s	$f2, var1		# load var1 in $f2
s.s	$f2, 20($sp)		# push $f2 on stack


li	$t3, 3			# $t3 = 3: number of floats

for1:
sub	$t3, $t3, 1		# decrement $t3
l.s	$f0, 4($sp)		# load first byte from stack in $f0
addi	$sp, $sp, 4		# increment stack pointer
li	$t7, 1			# preparation: $t7 = 1
li 	$t6, 0			# preparation: $t6 = 0
li	$t0, 1			# preparation: $t0 = 1
mfc1	$t2, $f0		# move from coprocessor: $t2 = $f0

for2:
and	$t1, $t2, $t0		# logical and: $t1 = $t2 AND $t0
sll	$t0, $t0, 1		# shift left logical: $t0 = $t0 * 2^1
bne	$zero, $t1, case_1	# if $t1 /= 0 branch to case_1
addi	$sp, -4			# decrement stack pointer
sw	$zero, 4($sp)		# push $zero (=0) on stack
b	go_on			# branch to go_on

case_1:
addi	$sp, -4			# decrement stack pointer
sw	$t7, 4($sp)		# push $t7 (=1) on stack

go_on:
addi	$t6, $t6, 1		# increment $t6
bne	$zero, $t0, for2	# if $t0 /= 0 branch to for2

li	$v0, 1			# print_int

for3:
lw	$a0, 4($sp)		# load in $a0 value from stack on address 4($sp)
addi	$sp, 4			# increment stack pointer
syscall				# print
sub	$t6, $t6, 1		# decrement $t6
bne	$zero, $t6, for3	# if $t6 /= 0 branch to for3
li	$v0, 4			# print_string
la	$a0, txt2		# load in $a0 address txt2 
syscall				# print "\n"

bne	$zero, $t3, for1	# if $t3 /= 0 branch to for1

li	$v0, 10			# exit
syscall

It works, but somehow I've got the impression, that it always returns the same numbers (even if I've changed the floating point numbers in the .data-section).
I've got no idea, where the problem could be... Maybe someones got a hint for me?
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Assembly Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

All times are GMT -4. The time now is 1:48 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC