🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: be.comp.programming
2 messages
2 total messages Started by Yaqub Ali Sheikh Sun, 21 Sep 2003 01:35
newbie asembly language question
#4021
Author: Yaqub Ali Sheikh
Date: Sun, 21 Sep 2003 01:35
90 lines
2686 bytes
hey whats up everyone
i need help in a assembly language program im making, im just getting
started in assembly language so this program is fairly simple
The program will run in a loop which will prompt the user to enter an
integer (a simple prompt will do). If the value entered is less than or
equal to 0 the loop will terminate. Otherwise the program will add up all
values from one to the user's chosen value and display the sum. (Please
compute this sum using a loop, not a formula.) i am using xspim to compile
it.and the language is RISC assembly language

here is what i have so far, but my logic on the loop doesnt work right, im
sortta confused on how for loops work in assmebly language or if i even need
a for loop for this
any suggestions on how to fix this?

#########################################

# Text Segment #

# #

#########################################



.text

.globl main

main:

la $a0, prompt # print prompt on screen

li $v0, 4 # system call to print

syscall

next:

li $v0, 5 # syscall 5 reads an integer

syscall

move $t3, $v0


add $t0, $t0, $v0 # adds the number to t0


move $a0, $t0 # print result

li $v0, 1

syscall


la $a0, endl # system call to print

li $v0, 4 # out a new line

syscall

blez $t3, done

li $t3, 0

bgez $t3, next # loop while user doesnt enter in 0


done:

li $v0, 10 # system call to exit

syscall


#########################################

# Data Segment #

# #

#########################################

.data

prompt: .asciiz "Enter in a a number and i will add that number to the last,
enter 0 to exit "

endl: .asciiz "\n"
Re: newbie asembly language question
#4024
Author: Nicolas Barbier
Date: Sun, 21 Sep 2003 09:52
63 lines
3002 bytes
Yaqub Ali Sheikh wrote:

> The program will run in a loop which will prompt the user to enter an
> integer (a simple prompt will do). If the value entered is less than or
> equal to 0 the loop will terminate. Otherwise the program will add up all
> values from one to the user's chosen value and display the sum. (Please
> compute this sum using a loop, not a formula.) i am using xspim to compile
> it.and the language is RISC assembly language

This looks like MIPS assembly for me. I'm not familiar with that, so
anything I say can be wrong.

> here is what i have so far, but my logic on the loop doesnt work right, im
> sortta confused on how for loops work in assmebly language or if i even
> need a for loop for this
> any suggestions on how to fix this?
> 
> .text
> .globl main
> main:
> la $a0, prompt # print prompt on screen
> li $v0, 4 # system call to print
> syscall
> next:
> li $v0, 5 # syscall 5 reads an integer
> syscall

You probably know what you're doing, but I wonder what operating system has
a syscall to read an integer like this?

> move $t3, $v0
> add $t0, $t0, $v0 # adds the number to t0

You seem to rely on the fact that t0 contains the value 0 at the start of
the program.

> move $a0, $t0 # print result
> li $v0, 1
> syscall

You seem to rely on the fact that t0 will still hold the same value after
the system call.

> la $a0, endl # system call to print
> li $v0, 4 # out a new line
> syscall
> blez $t3, done
> li $t3, 0
> bgez $t3, next # loop while user doesnt enter in 0

I suppose bgez means "branch if greater or equal to zero". You just zeroed
t3, so this test will always be true.

> done:
> li $v0, 10 # system call to exit
> syscall

Btw: I think a group on MIPS assembler is better suited for this question
:-).

-- 
Nicolas Barbier
Protecting innovation against patent inflation <url:http://swpat.ffii.org/>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads