943,787 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 11163
  • Assembly RSS
Jan 27th, 2007
0

print corresponding ascii for letters

Expand Post »
Assembly Syntax (Toggle Plain Text)
  1. ; Description: Program to input a character and then output it to the screen
  2. ; Registers used: ax, dx
  3. .model small
  4. .stack 100h
  5. .data
  6. .code
  7.  
  8. mov ah, 02h ; DOS function call 2, character output
  9. mov dl, 41h ; the character 041h (i.e.'A')
  10. mov cx, 26 ; start the counter at 26 in cx
  11. again: int 21h ; print character
  12. inc dl ; the next character into dl
  13. loop again ; subtract 1 from cx, if not zero jump back to again
  14. finish: mov ax, 4C00h ; Terminate program
  15. int 21h ; correctly
  16.  
  17. end

The above loops from capital A to Z and prints out all charaters.What I'm wondering is could the above loop be used to print out A-Z and its corresponding ASCII value (e.g)

A 65
B 66
C 67

I'm guessing I'll need a unconditional loop,and some sort of comparison check...anyones input as to how I would go about coding this would be very much appreciated.Thanks.
Last edited by brian.p; Jan 27th, 2007 at 6:56 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
brian.p is offline Offline
9 posts
since Jan 2007
Jan 31st, 2007
1

Re: print corresponding ascii for letters

Assembly Syntax (Toggle Plain Text)
  1. string db 4 dup( ' ' ), '$'
  2.  
  3. mov al, 41h ; the character 041h (i.e.'A')
  4. mov cx, 26 ; start the counter at 26 in cx
  5.  
  6. again:
  7. push ax ;save character
  8. mov string[ 0 ], al ;copy character to start of string
  9. mov bh, 10
  10. div bh ;MS digit of ascii code into al, LS digit into ah
  11. add ax, '00' ;convert digits into ascii codes
  12. mov word ptr string[ 2 ], ax ;copy digits into string
  13. mov ah, 9 ;print string
  14. int 21h
  15. pop ax ;retrieve character
  16. inc al ;next character
  17. loop again ; subtract 1 from cx, if not zero jump back to again
  18. finish: mov ax, 4C00h ; Terminate program
  19. int 21h ; correctly
Reputation Points: 14
Solved Threads: 4
Junior Poster
mathematician is offline Offline
149 posts
since Nov 2006
Mar 23rd, 2007
0

Re: print corresponding ascii for letters

Assembly Syntax (Toggle Plain Text)
  1. string db 4 dup( ' ' ), '$'
  2.  
  3. mov al, 41h ; the character 041h (i.e.'A')
  4. mov cx, 26 ; start the counter at 26 in cx
  5.  
  6. again:
  7. push ax ;save character
  8. mov string[ 0 ], al ;copy character to start of string
  9. mov bh, 10
  10. div bh ;MS digit of ascii code into al, LS digit into ah
  11. add ax, '00' ;convert digits into ascii codes
  12. mov word ptr string[ 2 ], ax ;copy digits into string
  13. mov ah, 9 ;print string
  14. int 21h
  15. pop ax ;retrieve character
  16. inc al ;next character
  17. loop again ; subtract 1 from cx, if not zero jump back to again
  18. finish: mov ax, 4C00h ; Terminate program
  19. int 21h ; correctly

thanks for the help,and sorry for my late reply...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
brian.p is offline Offline
9 posts
since Jan 2007
Mar 23rd, 2007
0

Re: print corresponding ascii for letters

If you use a mutant form of AAM or AAD (I forget which right now) that uses 16 as its base rather than 10, it will cleanly split the nibbles in AL into AH and AL.

IOW - 0x35 would become 0x0305
Reputation Points: 31
Solved Threads: 0
Light Poster
Purple Avenger is offline Offline
49 posts
since Jan 2007

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: Turn on a LED for 5 minutes Use PIC16F84A
Next Thread in Assembly Forum Timeline: MIPS64 assembly language





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


Follow us on Twitter


© 2011 DaniWeb® LLC