Assembly Language Programming 2
Input
Data Labels.
Data may be stored in memory in Pascal by declaring variables or constants.
Example
const length = 64;
What this really does is reserve a store location(s) in memory, labels it 'length' and places the number 64 in it.
If a variable is declared, then the number of bytes reserved by the compiler will depend on the type of variable...
| byte or char | : 1 byte (8 bits) |
| word | : 2 bytes (16 bits) |
| integer | : 2 bytes |
| longint | : 4 bytes |
Example program
This program reserves a store location 'fred'. The assembly language program stores the number 25 in 'fred' and then (in Pascal) we can check the contents of 'fred' by outputting it.
| program DataLabel; | ||||
| var | fred : byte; | {1 byte store location} | ||
| begin | ||||
| asm | {start of Assembly program} | |||
| mov fred,25 | {Place the number 25 into 'fred'} | |||
| end; | {end of Assembly language} | |||
| writeln(fred) | {Pascal output} | |||
| end. | ||||
Input
Both Input and Output is carried out by resident interrupt routines. (This is good news because it means we don't have to write input and output routines ourselves!)
Keyboard Read
1. Set [AH] = 1 and call Interrupt 21H. (H stands for Hexadecimal)
This function waits for you to type a character at the keyboard.
It echos the character on the screen and places the ASCII code in register [AL].Insert the two lines of code....
MOV AH,1 INT 21H
...into your program, and the computer will wait for input. If the user then types the letter 'A' for example, the number 65 would be placed in the register [AL].
2. Set [AH] = 8 and call Interrupt 21H.
This function reads a character from the keyboard and places the ASCII code in [AL] but does not echo the character on the screen.
(Useful for password routines etc!!)
Exercise
Write a program which allows you to type a character at the keyboard and it outputs the ASCII code for that character.
(a) Declare a variable called 'Code'
(b) In an Assembly language routine, input a character and move the ASCII code into 'Code'.
(c) In PASCAL, output the value of variable 'Code'
(d) Test your program works...'A' should give you 65.
(e) Use your program to find the ASCII code of the characters...