Need help in LC# code

Reply

Join Date: Nov 2006
Posts: 8
Reputation: qaizaar is an unknown quantity at this point 
Solved Threads: 0
qaizaar qaizaar is offline Offline
Newbie Poster

Need help in LC# code

 
0
  #1
Nov 5th, 2006
how do i read an input in LC-3 where it checks for yes or no as an answer to a prompt and returns 1 if yes and no if 0. thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,142
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1434
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Need help in LC# code

 
0
  #2
Nov 6th, 2006
you should probably get the recommended book Introduction to Computing Systems: From Bits and Gates to C and Beyond and read it. I don't know the first thing about it, so can't help you.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 14
Reputation: c0dex has a little shameless behaviour in the past 
Solved Threads: 1
c0dex's Avatar
c0dex c0dex is offline Offline
Newbie Poster

Re: Need help in LC# code

 
-1
  #3
Dec 4th, 2008
You're just in luck. I just finished writing a similar subroutine for my assembly class (uses the same textbook as mentioned above) to ask if someone wants to play again (we've made the game pong breakout). The following code is documented well enough for you to understand it clearly.

  1. ;
  2. ; Prompts the user for something.
  3. ;
  4. ; Preconditions:
  5. ;
  6. ; TRAP x42 must be implemented in the OS in a way that it does not wait
  7. ; for a key to be pressed. It should only check if a key's pressed once.
  8. ;
  9. ; Must use the following declarations.
  10. ;
  11. ; PROMPT .STRINGZ "Would you like to do something (y/n)? "
  12. ; HEX_Y1 .FILL x79 ; hex for 'y'
  13. ; HEX_Y2 .FILL x59 ; hex for 'Y'
  14. ; HEX_N1 .FILL x6E ; hex for 'n'
  15. ; HEX_N2 .FILL x4E ; hex for 'N'
  16. ;
  17. ; Postconditions:
  18. ;
  19. ; If yes, return 1 in R0.
  20. ; If no, return 0 in R0.
  21. ;
  22. PROMPT_SR
  23. LEA R0, PROMPT ; Load PROMPT to R0 be a string.
  24. TRAP x22 ; Print the string in R0.
  25.  
  26. POLL TRAP x42 ; Get the key press. (This code assumes that
  27. ; TRAP x42 does not wait for a key to be pressed.
  28.  
  29. LD R4, HEX_Y1 ; Load the hex value for 'y'.
  30. NOT R4, R4; ; Get the 2's compliment
  31. ADD R4, R4, #1 ;
  32. ADD R4, R5, R4 ; R4 = R5 - R4
  33.  
  34. BRz YES ; If R5 is zero, then 'y' was pressed.
  35.  
  36. LD R4, HEX_Y2 ; Load the hex value for 'Y'.
  37. NOT R4, R4; ; Get the 2's compliment
  38. ADD R4, R4, #1 ;
  39. ADD R4, R5, R4 ; R4 = R5 - R4
  40.  
  41. BRz YES ; If R5 is zero, then 'Y' was pressed.
  42.  
  43. LD R4, HEX_N1 ; Load the hex value for 'n'.
  44. NOT R4, R4; ; Get the 2's compliment
  45. ADD R4, R4, #1 ;
  46. ADD R4, R5, R4 ; R4 = R5 - R4
  47.  
  48. BRz NO ; If R5 is zero, then 'n' was pressed.
  49.  
  50. LD R4, HEX_N2 ; Load the hex value for 'N'.
  51. NOT R4, R4; ; Get the 2's compliment
  52. ADD R4, R4, #1 ;
  53. ADD R4, R5, R4 ; R4 = R5 - R4
  54.  
  55. BRz NO ; If R5 is zero, then 'N' was pressed.
  56.  
  57. BRnzp POLL ; y/Y or n/N has not bee pressed, so poll again.
  58.  
  59. YES:
  60. AND R0, R0, #0 ; Clear R0.
  61. ADD R0, R0, #1 ; Add one to R0.
  62. RET
  63.  
  64. NO:
  65. AND R0, R0, #0 ; Clear R0.
  66. RET
Last edited by c0dex; Dec 4th, 2008 at 11:29 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC