•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 455,986 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 3,802 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: Programming Forums
Views: 724 | Replies: 1
![]() |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I'm taking a class in sparc assembly, and I'm having a hard time with this concept. We're supposed to add two numbers together that can have as many as 100 digits. Since this is too many to fit into one register, I have to save them in memory and then deal with them. This is the part that I can't figure out. When saving it, should I use %d or %s? I'm saving the input in a variable that I declared like this: input1:.skip 4 * 50. Also, I was planning on using addx and addxcc to keep the carry and was planning on loading up 32 bits at a time and adding that and then restoring it, but I can't figure it out.
Am I going about this in the right way? Does anyone have any suggestions? Thanks in advance!
I was thinking I was having a problem with the load and store part of things... What do you think?
Am I going about this in the right way? Does anyone have any suggestions? Thanks in advance!
.section ".data" format: .asciz "%s%c" displayformat: .asciz "%d\n" prompt1: .asciz "Enter first number (100 digit max): " prompt2: .asciz "Enter second number (100 digit max): " sDisplaySum: .asciz "\nThe sum is: %d" sDisplayDiff: .asciz "\nThe difference is: %d" nl: .byte '\n' .align 4 .section ".bss" input1: .skip 4 * 50 input2: .skip 4 * 50 sum: .skip 4 * 50 diff: .skip 4 * 50 .align 4 findSumDiff: save %sp, -96, %sp!can not be leaf b/c must call validate subroutine !use a loop to continue to load .words and check each time to see if %l1 and %l2 are 0 !use addxcc and mov 0, %l3!set byte counter to loop set input1, %l0!load first 32 bits to add ld [%l0 + %l3], %l1!first number set input2, %l0!load first 32 bits to add ld [%l0 + %l3], %l2!second number addcc %l1, %l2, %l4!does first add and sets the carry flag set sum, %l5 st %l4, [%l5 + %l3]!store the first part of the sum into memory add %l3, 4, %l3!increment counter addloop: set input1, %l0!loads the next 32 bits of first number ld [%l0 + %l3], %l1 set input2, %l0!loads the next 32 bits of second number ld [%l0 + %l3], %l2 addxcc %l1, %l2, %l4!adds in carry to the addition, adds, then sets the flag again set sum, %l5 st %l4, [%l5 + %l3]!store the first part of the sum into memory add %l3, 4, %l3!increments counter again cmp %l3, 200 bne addloop nop ret restore
I was thinking I was having a problem with the load and store part of things... What do you think?
Last edited by Ancient Dragon : Dec 3rd, 2007 at 10:24 am. Reason: corrected code tags
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
I know nothing about SunSparc assembly, but I think your problem is in mixing data types.
When the user inputs a number, like 1230, that's four ASCII characters: 49, 50, 51, and 48.
So, you need to decide what kind of numbers you intend to add: binary or ASCII? (I think for your problem you might want to do the latter.)
There must be at some point, no matter which way you do it, conversion between the ASCII representation (received from the user and printed out when done) and something that can be added.
If you do the ASCII one digit at a time, you only need to remember a carry flag each addition:
1224
2199
start with carry of 0
'4'-'0'= 4
'9'-'0'= 9
4+9+carry=13: carry is 1, result is 3
3+'0'= '3'
'2'-'0'= 2
'9'-'0'= 9
2+9+carry=12: carry is 1, result is 2
2+'0'= '2'
'2'-'0'= 2
'1'-'0'= 1
2+1+carry=4: carry is 0, result is 4
4+'0'= '4'
etc.
Hope this helps.
When the user inputs a number, like 1230, that's four ASCII characters: 49, 50, 51, and 48.
So, you need to decide what kind of numbers you intend to add: binary or ASCII? (I think for your problem you might want to do the latter.)
There must be at some point, no matter which way you do it, conversion between the ASCII representation (received from the user and printed out when done) and something that can be added.
If you do the ASCII one digit at a time, you only need to remember a carry flag each addition:
1224
2199
start with carry of 0
'4'-'0'= 4
'9'-'0'= 9
4+9+carry=13: carry is 1, result is 3
3+'0'= '3'
'2'-'0'= 2
'9'-'0'= 9
2+9+carry=12: carry is 1, result is 2
2+'0'= '2'
'2'-'0'= 2
'1'-'0'= 1
2+1+carry=4: carry is 0, result is 4
4+'0'= '4'
etc.
Hope this helps.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Assembly Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- barred from IT, thinking of returning (IT Careers and Business)
- User Input (scanf) in SPARC? (Assembly)
- Your opinion of Assembly: (Assembly)
- sparc assembler under linux (Assembly)
- Question: Where are good Assembly Compilers? (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: Simple Assembly Question on Strings
- Next Thread: Having trouble ENCODING/DECODING ASSEMBLY



Linear Mode