0

am using EMU8086 i wan to print ascii value of string like "ABC" output is: "65" "66" "67". please guide me how to print ascii value of string when user input the value.

am also print character with the help of ascii table but i don't know how to print ascii value of character

Zulfiqar Khan
  • 11
  • 2
  • 5
  • Treat each byte as a number and print an ASCII decimal string representation of that number. [Displaying numbers with DOS](https://stackoverflow.com/q/45904075) – Peter Cordes Jun 18 '20 at 13:42

1 Answers1

0

This is the Solution for your Problem

org 100h
.data
mystr DB 'A','B','C'
RES  DB 10 DUP ('$')  
.code
; Print the ASSCII for A
lea si,mystr[0]
mov AX,[si]
mov ah,0
    LEA SI,RES
    CALL HEX2DEC
    LEA DX,RES
    MOV AH,9
    INT 21H
; Print the coma
mov dl,','
mov ah,2
int 21h 
; Print the ASSCII for B    
lea si,mystr[1]
mov AX,[si]
mov ah,0
    LEA SI,RES
    CALL HEX2DEC
    LEA DX,RES
    MOV AH,9
    INT 21H 
; Print the coma
mov dl,','
mov ah,2
int 21h
; Print the ASSCII for C
lea si,mystr[2]
mov AX,[si]
mov ah,0
    LEA SI,RES
    CALL HEX2DEC
    LEA DX,RES
    MOV AH,9
    INT 21H 
    MOV AH,4CH
    INT 21H         
HEX2DEC PROC NEAR
    MOV CX,0
    MOV BX,10
LOOP1: MOV DX,0
       DIV BX
       ADD DL,30H
       PUSH DX
       INC CX
       CMP AX,9
       JG LOOP1
       ADD AL,30H
       MOV [SI],AL
LOOP2: POP AX
       INC SI
       MOV [SI],AL
       LOOP LOOP2
       RET
HEX2DEC ENDP           
END START 




ret 

END
Usman Ghani Mughal
  • 613
  • 2
  • 7
  • 14
  • Good answers should explain the big picture in words, not just a code dump. Also, it appears your `HEX2DEC` function takes an number in a register as input. That's not hex; hex is a text serialization format for numbers. If anything, integers in registers are in binary. That's why a left-shift by 1 multiplies by 2, the number base of the binary representation that computers use to hold numbers. Not by 16 (one hex digit). I might call that function `Int2Dec`. – Peter Cordes Jun 18 '20 at 15:49
  • BTW, instead of using 2 loops and push/pop, you can just decrement a pointer starting from the end of a buffer ([like this](https://stackoverflow.com/a/46301894)). If you're going to just print it as a `$`-terminated string, you want a constant end-point. BTW, your function looks buggy if you have a mix of 3-digit and 2-digit characters. Try it with `'a', 'z', 'a'` and notice that `122` the last `a` will print as `972` because you leave the `122` in the RES buffer. Starting from a fixed end and decrementing a pointer would fix this problem for free; you return the start pointer. – Peter Cordes Jun 18 '20 at 15:57
  • but! here you initialize the values first then you print the ASCII value of character one by one what you initialize it....but here is not my question my question is that if we enter the string "ABC" and then they convert the String in ASCII value against the string what user enter. – Zulfiqar Khan Jun 19 '20 at 06:26
  • i think this kind of code already available on the STACK....someone did it already but they get the value form user only one character at a time and here you just initialize the value first and call him separately all character. – Zulfiqar Khan Jun 19 '20 at 06:31