Professional Documents
Culture Documents
Character Representation
All data, characters must be coded in binary to be processed by the computer. ASCII:
American Standard Code for Information Interchange Most popular character encoding scheme. Uses 7 bit to code each character. 27 = 128 ASCII codes. Single character Code = One Byte [7 bits: char code, 8th bit set to zero] 32 to 126 ASCII codes: printable 0 to 31 and 127 ASCII codes: Control characters
Example
0
1 2 3
R
G Space 2
52
47 20 32
0101 0010
0100 0111 0010 0000 0011 0010
7A
0111 1010
The Keyboard
Identifies a key by generating an ASCII code when the key is pressed. ASCII Keyboard Scan Code
How to Convert?
If a byte contains the ASCII code of an uppercase letter, what hex should be added to it to convert to lower case?
If a byte contains the ASCII code of a decimal digit, What hex should be subtracted from the byte to convert it to the numerical form of the characters?
Sample Programs
Program 1: Echo
TITLE MY First Program .MODEL SMALL .STACK 100H .CODE ;display prompt MOV AH, 2 ;display character function MOV DL, '?' ;character is '?' INT 21H ;display it ;input a character MOV AH, 1 ;read character function INT 21H ;character in AL MOV BL, AL ;save it in BL
Contd..
;go to a new line MOV AH, 2 MOV DL, 0DH INT 21H MOV DL, 0AH INT 21H ;display character MOV DL, BL INT 21H ;return to DOS MOV AH, 4CH INT 21H
Program 2: Add
.DATA A DW 2 B DW 5 SUM DW ? .CODE ;add the numbers MOV AX, A ADD AX, B MOV SUM, AX ;exit to DOS MOV AX, 4C00H INT 21H
10
(hello.asm)
; This program displays Hello, world! .model small .stack 100h comment line memory model
halts program
Contd..
;print user prompt LEA DX, MSG1 ;get first message MOV AH, 9 ;display string function INT 21H ;display first message ;input a character and convert to upper case MOV AH, 1 ;read character function INT 21H ;read snall letter into AL SUB AL, 20H ;convert it into uppercase MOV CHAR, AL ;and store it ;display on the next line LEA DX, MSG2 ;get second message MOV AH, 9 ;display string function INT 21H ;display message and upper case letter in front ; 15
References
Chapter 2 & 4, Ytha Yu and Charles Marut, Assembly Language Programming and Organization of IBM PC
17