Q. Program for encoding ASCII Alpha numeric?
; A program for encoding ASCII Alpha numeric.
; ALGORITHM:
; create the code table
; read an input string character by character
; translate it using code table
; output the strings
DATA SEGMENT
CODETABLE DB 48 DUP (0); no translation of first
; 48 ASCII
DB '4590821367'; ASCII codes 48 -
; 57 ≡ (30h - 39h)
DB 7 DUP (0); no translation of these 7 characters
DB 'GVHZUSOBMIKPJCADLFTYEQNWXR'
DB 6 DUP (0); no translation
DB 'gvhzusobmikpjcadlftyeqnwxr'
DB 133 DUP (0); no translation of remaining
; Character
DATA ENDS
CODE SEGMENT
MOV AX, DATA
MOV DS, AX ; initialize DS
MOV BX, OFFSET CODETABLE; point to lookup table
GETCHAR:
MOV AH, 06; console input no wait
MOV DL, 0FFh ; specify input request
INT 21h; call DOS
JZ QUIT ; quit if no input is waiting
MOV DL, AL ; save character in DL
XLAT CODETABLE; translate the character
CMP AL, 0; translatable?
JE PUTCHAR ; no: write it as is.
MOV DL, AL; yes: move new character
; To DL
PUTCHAR:
MOV AH, 02 ; write DL to output
INT 21h
JMP GETCHAR; get another character
QUIT: MOV AX, 4C00h
INT 21h
CODE ENDS
END
Discussion:
The program above will code the data. For illustration a line from an input file will be encoded:
A SECRET Message (Read from an input file)
G TUHFUY Juttgou (Encoded output)
The program above can be run by using following command line. If program file name is coding.asm
Coding infile > outfile
The infile is input data file and outfile is output data file.
You can write more such applications by using 8086 assembly tables.