FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


assembly language problem





riyadh
i need to write a looping program in intel 8086 assembly language to add these numbers -
1 + 3 + 7 + 13

only the basic commands can be used like MOV, LOOP, ADD, SUB, MUL, DIV etc. no arrays can be used.

can anyone help?
davidv
riyadh wrote:
i need to write a looping program in intel 8086 assembly language to add these numbers -
1 + 3 + 7 + 13

only the basic commands can be used like MOV, LOOP, ADD, SUB, MUL, DIV etc. no arrays can be used.

can anyone help?


I don't have much experience with assembly let alone Intel's assembly however I do know a little bit of ARM. My solution isn't very memory efficient cause I'm using 5 registers
(among many other things), however here it is anyway. If you have any questions, please let me know. Smile

Code:
.text

ldr r0, =table
ldr r1, =length
ldr r1, [r1]

ldr r2, =count
ldr r2, [r2]

mov r3, #0

loopa:
   cmp r2, r1
   beq end_loop   
   ldr r4, [r0]
   add r3, r3, r4
   add r2, r2, #1
   add r0, r0, #4
   b loopa

end_loop:

.data

table: .word 1, 3, 7, 13
length: .word 4
count: .word 0

.end
riyadh
thnx for the reply but i am not allowed to use arrays. i need to do this using the basic arithmetic operations, loops and the available registers. using an array would've made my life easier
davidv
Alternatively, you could store each value in it's own label where each label is contiguous with 4 bytes of separation hence the add r0, r0, #4

Code:
.text

ldr r0, =x
mov r1, #4 @ total number of values to add 
mov r2, #0 @ the sum

loopa:
   @ Sential value, 0
   ldr r4, [r0]
   cmp r4, #0
   beq end_loop   
   
   add r2, r2, r4
   add r0, r0, #4
   b loopa

end_loop:

.data
   x: .word 1
   y: .word 3
   z: .word 7
   w: .word 13
   sent: .word 0 @ stops here
.end


The solution is very specific to your problem. Then again, your problem was a specific problem to begin with. Confused

No arrays were used. Hope this helps

Note: There aren't any loops in ARM but rather branches which are essentially GOTO statements. Of course these branches allow conditions such as beq (branch if equal, based on the previous comparison), or ble, bgt, bcs etc. If in any way you want to branch to a subroutine and then go back to where you've branched from, you need a branch link. The branch alone doesn't store the calling location in r14 which makes it impossible to return. So instead, a blle should be used (branch link if less than).
riyadh
thnx...rly helped...and talking about unique problems...tell me about it!!! Razz good on ya mate
davidv
riyadh wrote:
thnx...rly helped...and talking about unique problems...tell me about it!!! Razz good on ya mate


Glad I could help! Smile
Anahit
Can you help me please to write a problem with assembly language commands.
I really need a help.
Thank you.
Related topics
What computer languages you know?
Complete Tutorial LINKS for every language
Learn Assembly: the LUCID way
Help In ASSEMBLY Language
A lot of MSN Messenger resources
Decimal, Binary and Hexadecimal
Do you code HTML or do you use wysiwyg editors?
Knowing Source Code
assembly compiler problem
which one programming lanuge result's the best speed
Game Maker
ANYONE THINKS TIME TRAVEL IS POSSIBLE?
What Are Viruses
Keyboard Language Problem with Windows XP SP2
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.