Article View: be.comp.programming
Article #4024Re: newbie asembly language question
From: Nicolas Barbier
Date: Sun, 21 Sep 2003 09:52
Date: Sun, 21 Sep 2003 09:52
63 lines
3002 bytes
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/>
Technical Details
Message-ID:
<3f6d7551$0$1129$6c56d894@feed0.news.be.easynet.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!npeer.de.kpn-eurorings.net!newsfeed.tiscali.ch!feed1.news.be.easynet.net!feed0.news.be.easynet.net!not-for-mailReferences:
<Hf7bb.1631$a16.663@lakeread01>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcea4,985ef1a80d1bafc4 X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2003-09-21 02:54:36 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!npeer.de.kpn-eurorings.net!newsfeed.tiscali.ch!feed1.news.be.easynet.net!feed0.news.be.easynet.net!not-for-mail Message-ID: <3f6d7551$0$1129$6c56d894@feed0.news.be.easynet.net> From: Nicolas Barbier <reply@in.group.invalid> Subject: Re: newbie asembly language question Newsgroups: be.comp.programming Date: Sun, 21 Sep 2003 11:52:55 +0200 References: <Hf7bb.1631$a16.663@lakeread01> User-Agent: KNode/0.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Lines: 63 Organization: [ posted via Easynet Belgium ] NNTP-Posting-Date: 21 Sep 2003 09:54:26 GMT NNTP-Posting-Host: 213.193.183.28 X-Trace: 1064138066 feed0.news.be.easynet.net 1129 [::ffff:213.193.183.28]:32794 X-Complaints-To: abuse@be.easynet.net