943,965 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 623
  • Assembly RSS
Oct 21st, 2009
0

help with assembly assignment

Expand Post »
so I am working on an assignment in class, and I've hit a road block. the assignment is to replace certain letters (b, c) with others, (x, y). Right now, my program is not recognizing 'b' in ebx, and the second letter in the array, 'b', (stored in eax) as being the same, so it is not changing them. I know im doing something wrong, but I can't figure out what. Any hints would be much appreciated, meanwhile i will keep plugging away at it. Also, I cannot get the new array in edx to show up without subtracting sixteen, and im not sure how to fix that so that is not necessary. Thanks so much.

assembly Syntax (Toggle Plain Text)
  1.  
  2. INCLUDE Irvine32.inc
  3. .data
  4. array byte 'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c',
  5. 'd', 'e', 'f', 'a', 'b', 'c'
  6. letter byte ?
  7. newArray byte 15 dup (?)
  8. .code
  9. main PROC
  10. mov ecx, lengthof array ;moves ecx to beginning of array as a counter
  11. mov esi, offset array ;moves esi to the beginning of array to obtain letters
  12. mov eax, [esi] ;moves first position of array into eax
  13.  
  14. doLoop: ;starts a loop
  15. mov ebx, 'b' ;moves first letter comparison (b) into ebx
  16. cmp ebx, eax ;compares letters
  17. je check4C ;if it is b, then jump to check for c
  18. add edx, eax ;if not b, store first letter of newArray in edx
  19. add esi, type array ; increment esi to next letter in array
  20.  
  21. loop doLoop ;loop back to the beginning
  22.  
  23. mov edx, offset newArray
  24. sub edx, 16
  25.  
  26. call writestring ;print newArray string with new letters
  27. call crlf ;enters a blank line
  28. call waitmsg ;waits til user closes screen
  29.  
  30. exit ;exit
  31.  
  32. check4C: ;check for c
  33. add edx, 'x' ;adds x for b into new array
  34. add esi, type array ;move esi down the array
  35. mov eax, [esi] ;move esi into eax for next comparison
  36. mov ebx, 'c' ;move c into ebx for comparison
  37. cmp ebx, eax ;compare registers
  38. je replace ;if the letter is matches c go to replace
  39. add edx, eax ;store next letter of newArray in edx
  40. add esi, type array ;move esi down the array
  41. jmp doLoop ;go to the top of the loop
  42.  
  43. replace: ;replaces y for c
  44. add edx, 'y' ;moves y into array instead of c
  45. add esi, type array ;move esi down the array
  46. jmp doLoop ;go to the top of the loop
  47.  
  48. main ENDP
  49.  
  50. END main
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amw2326 is offline Offline
1 posts
since Oct 2009
Oct 21st, 2009
0
Re: help with assembly assignment
mov eax, dword [esi] ;moves first position of array into eax
And also moves a double word EAX=44434241h, I think so,
not sure.


To read each byte at a time do:
xor eax, eax
mov al, byte [esi]

mov ebx, 'b' ;moves first letter comparison (b) into ebx
cmp ebx, eax ;compares letters EAX=44434241h EBX=00000042h
je check4C
Last edited by NotNull; Oct 21st, 2009 at 10:10 pm.
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: hlt Instruction
Next Thread in Assembly Forum Timeline: add





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC