The majority of forums are now only available as archives, which means posting/editing is disabled.
The Anything and Everything forum is still open.
The Anything and Everything forum is still open.
Help please!
|
|||
|
Rank: ? (2)
Member #: 24495 |
Hello
I have to write a program that will input a list of positive 2-digit integrs and will compute the sum of all the numbers that are multiples of three and print out the sum. The numbers are to be 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. Well so far I have the program working with an input of a list of positives 1-digit integers; now I want you to help me to change the program so it will have a input of a list of 2-digit integers. Please help me I really need your help. Here is the code that I have: 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[/code please I would appreciate your help. Thank you » Post edited 2005-06-25, 02:22pm by vallea.
|
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
it's generally helpful to post what kind of assembly you're using -- looks like 68k, but that doesn't matter for what i'm going to say:
to read in a decimal number with more than one digit, use the following steps in a loop until there are no more digits to read: multiply current number by 10 add digit read next digit
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: ? (2)
Member #: 24495 |
Thank you I have the program running with 2 digit integer, but now I need to compute the sum of all the numbers that are multiples of three and print out the sum or if there are not multiples print out the prompt in address error
I have beein trying but I can not get it. please help me. ex: input 12, 11, 18, 23 00 the output will be The sum of the multiples of three is 30 I would appreciate any help Thank you |
||
|
Please login or register to post a reply.
