print corresponding ascii for letters

Reply

Join Date: Jan 2007
Posts: 9
Reputation: brian.p is an unknown quantity at this point 
Solved Threads: 0
brian.p brian.p is offline Offline
Newbie Poster

print corresponding ascii for letters

 
0
  #1
Jan 27th, 2007
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 134
Reputation: mathematician is an unknown quantity at this point 
Solved Threads: 3
mathematician mathematician is offline Offline
Junior Poster

Re: print corresponding ascii for letters

 
1
  #2
Jan 31st, 2007
  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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 9
Reputation: brian.p is an unknown quantity at this point 
Solved Threads: 0
brian.p brian.p is offline Offline
Newbie Poster

Re: print corresponding ascii for letters

 
0
  #3
Mar 23rd, 2007
Originally Posted by mathematician View Post
  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...
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 49
Reputation: Purple Avenger is an unknown quantity at this point 
Solved Threads: 0
Purple Avenger Purple Avenger is offline Offline
Light Poster

Re: print corresponding ascii for letters

 
0
  #4
Mar 23rd, 2007
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
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC