Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 23rd, 2005, 9:37 PM   #1
vallea
Newbie
 
Join Date: Jun 2005
Posts: 1
Rep Power: 0 vallea is on a distinguished road
[LC-3] HELP! assembly program

Hello

I need help with a program. I have to write a program that will input a list of positives 2-digit integers and will compute the sum of all the numbers that are multiples of 3 and print out the sum. The numbers are to input from the keyboard after a prompt is written on the monitor. The value zero will act as a sentinel value at the end of the data output is to be as follows:

The sum of the multiples of three is the vaule of the sum
or
There are no multiples of three in the list

the program should work for a sum less than 100.

I have being working on it and so far I have the program, but working with input of a list of positives 1-digit integers. And here is the code.




	.ORIG	X3000
	  LD	R2, CHANGE	  	;FFD0 in R2
	 LD 	R4, CHANGE2		;0030  in R4
	 AND 	R6, R6, #0 		;
	 ADD	R1, R5, #1	  	;1 in R1
LOOP	 ADD	R5, R1, #0	  	; 1 in R5
	 BRz	END		  	;if R5 = 0 then go to END
	 	
	 TRAP	x23		 	;print a prompt on the screen and read a single 						 ;character from the keyboard its  ascii code àR0 
	 ADD	R1, R0, R2       	;ASCII prompt + ffd0 à R1
	 ADD	R7, R1, #-3	 	;result in R1  - 3 à R7
	 BRz	GETNUM	  		;if R7 = 0 go to GETNUM
	 
	 ADD	R7, R1, #-6	 	;result in R1 -3 à R7
	 BRz	GETNUM	 		;if R7	= 0 go to GETNUM
	 
	 ADD	R7, R1, #-9	 	;result in R1 -3 à R7
	 BRz 	GETNUM	 		;if R7	= 0 go to GETNUM
	 BR	ENDIF		 	;Go to ENDIF

GETNUM   ADD	R6, R6, R1	 	;Ascii value goes to R6
ENDIF	 BR	LOOP		 	;Go to LOOP
END	 AND 	R1, R1, #0	 	;clear R1
	 AND	R2, R2, #0	 	;clear R2
	 AND	R3, R3, #0	  	;clear R3
	 ADD	R1, R6, #0	 	;Ascci value goes to R1
	 BRz	RESULT1	 		;if R1 = 0 go to RESULT1
	 BRp	RESULT2	 		;if R2 = positive # go to RESULT2
					;
RESULT1	 LEA	R0, ERROR     		;address of ERROR à R0  
	 TRAP	x22		 	;write a string of ascii characters to the console
	 TRAP	x25		 	;halt execution and print a message on the console 
					;
RESULT2	 LEA	R0, MESSAGE 		;address of MESSAGE à R0
	 TRAP	x22		  	;write a string of ascii characters to the console
	 ADD	R1, R6, #-9       	;
	 BRnz	RESULT3        		;If  R1 = - or 0 go to  RESULT3
	 BR	RESULT4	 		;Go to RESULT4
					;
RESULT3	 ADD	R6, R6, R4	 	;ASCII value + 0030 à R6
	 ADD	R0, R6, #0	 	;what is in R6 à R0
	 TRAP	x21		 	;Write a character in R0 to the console display
	 TRAP	x25		 	;halt execution and print a message on the console 
					;
RESULT4	 ADD 	R0, R6, #0		; what is in R6 à R0
WHILE	 ADD	R0, R0, #-10		;what is in R6 - 10 à R0
					;
	 BRzp	DOBODY			;if R0 = 0 or positive go to DOBODY
	 BR	ENDWHILE		;go to ENDWHILE
					;
DOBODY	 ADD	R3, R3, #1		;increment R3
	 BR 	WHILE			;go to WHILE
					;
ENDWHILE ADD	R2, R0, #0		;result of R0 goes into R2
	 ADD 	R2, R2, #10		;
	 ADD	R0, R3, R4		;
	 TRAP 	x21			;Write a character in R0 to the console display
					;
	 ADD	R0, R2, R4		;
	 TRAP	x21			;Write a character in R0 to the console display
	 TRAP 	x25			;halt execution and print a message on the console 
					;
MESSAGE	 .STRINGZ " The sum of the multiples of three is:"
ERROR	 .STRINGZ "There are no multiples of three in the list"
CHANGE	 .FILL	XFFD0
CHANGE2	.FILL	x0030	
		.END

I would really appreciate any help. Thank you

Last edited by vallea; Jun 23rd, 2005 at 9:49 PM.
vallea is offline   Reply With Quote
Old Jun 24th, 2005, 8:17 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You say it's working, but you need help. That's not a lot of information. The only inference I can draw is that you don't know how to grab two input characters and make one number from them. Would that be correct?

Consider your posts very carefully, as psychic phenomena are not available on an everyday basis. Perhaps read the "How to post..." thread in the C forum. Effective question asking is essential to efficient resolution.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 26th, 2005, 7:55 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I don't know if you're following your thread, have found your answer, have said, "Oh, shoot!", and thrown your hands into the air and given up, or what. I took the time to download information on your "processor" and play with it a bit. It isn't a real processor in the sense that it has been implemented in hardware; it's strictly a simulator.

It has a very limited instruction set. That's not a Bad Thang for learning; one can implement anything with an AND, a NOT, and some transfer-of-control mechanisms. It does make things a bit difficult. It doesn't even have simple bit-shift capabilities, which one would want to write effective multiply/divide routines, ASCII-to-numeric conversions, and stuff of that nature. It does have a stack that is used to keep track of things for traps and interrupts, but the stack isn't readily available to the user. There are no pushes or pops. The JSR (jump-to-subroutine) instruction puts the return address in a register and the RET instruction gets it from there. The upshot of all this is that one can't write nested calls or reentrant procedures.

The first thing that I would do if I were using this thing for more than, say, two or three tiny programs, would be to write some little utility subroutines. I'd implement my own stack, write a Push and a Pop, write a Call and a Return, write a left shift, a zero-extended right shift, and a sign-extended right shift. Then I'd write a multiply routine and a divide routine. The divide routine could provide the means of writing a modulus routine.

When I had all that available (and I do have some of it written), I'd write a routine to get a number from multiple keystrokes. THEN, given all that, I'd write your program as you explain it.

Even if you've run in ever-tightening circles until you've disappeared up your trailing orifice, I thank you for the spur. I haven't gone this low in years (well, not programmatically speaking, that is ). We used to do this stuff while we were cruising around on Noah's Ark waiting for the rain to let up. The pitiful thing about that is that it was marketable product! :eek:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:01 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC