Coal Lab 03 Solutions
Coal Lab 03 Solutions
Wah Campus
Here are the key points to understand and guidelines for using
emu8086.inc effectively:
●
● This makes functions like print_string, print_num, putc,
etc., available in your code.
.model small
.stack 100h
.data
.code
start:
mov ds, ax
print_string myString
; Terminate program
int 0x21
●
● Notice the $ symbol at the end of the string. This is
important because print_string uses the '$' terminator to
know where the string ends.
3. Printing Numbers Using print_num
.model small
.stack 100h
.data
.code
start:
mov ds, ax
mov ax, 78
print_num ax
; Terminate program
int 0x21
●
● Important: Make sure the number fits within the signed 16-
bit range (i.e., -32768 to 32767). If you try to print
numbers beyond that range, it may display incorrectly.
.model small
.stack 100h
.code
start:
mov ds, ax
; Terminate program
mov ah, 0x4C
int 0x21
●
● This is useful when you need to print characters at specific
locations or control their placement more precisely.
Syntax:
asm
Copy code
gotoxy row, column
.model small
.stack 100h
.code
start:
mov ds, ax
; Move cursor to row 5, column 10 and print 'X'
gotoxy 5, 10
putc
gotoxy 8, 15
putc
; Terminate program
int 0x21
● The scan_num macro reads a signed integer from the user and
stores the result in the ax register.
.stack 100h
.code
start:
mov ds, ax
scan_num
print_num ax
; Terminate program
int 0x21
●
● Note: You need to handle input carefully, especially when
dealing with signed numbers.
Example:
asm
Copy code
include 'emu8086.inc'
.model small
.stack 100h
.data
.code
start:
mov ds, ax
print_string message
; Terminate program
int 0x21
Summary:
mov ds, ax
print_string myString
; Terminate program
int 0x21
●
● Notice the $ symbol at the end of the string. This is important because
print_string uses the '$' terminator to know where the string ends.
.model small
.stack 100h
.data
.code
start:
mov ds, ax
; Set number in AX register (e.g., 78)
mov ax, 78
print_num ax
; Terminate program
int 0x21
●
● Important: Make sure the number fits within the signed 16-bit range (i.e., -32768 to
32767). If you try to print numbers beyond that range, it may display incorrectly.
● putc is used to print a single character to the screen. You place the ASCII value of the
character in the al register.
.model small
.stack 100h
.code
start:
; Terminate program
int 0x21
●
● This is useful when you need to print characters at specific locations or control their
placement more precisely.
● The gotoxy macro moves the cursor to a specified row and column on the screen.
Syntax:
asm
Copy code
gotoxy row, column
.model small
.stack 100h
.code
start:
mov ds, ax
gotoxy 5, 10
putc
gotoxy 8, 15
putc
; Terminate program
int 0x21
.model small
.stack 100h
.code
start:
mov ds, ax
scan_num
print_num ax
; Terminate program
int 0x21
●
● Note: You need to handle input carefully, especially when dealing with signed numbers.
● To display multi-line text using print_string, you can include newline characters
(ASCII code 0x0D for carriage return and 0x0A for line feed) in your strings.
Example:
asm
Copy code
include 'emu8086.inc'
.model small
.stack 100h
.data
.code
start:
mov ds, ax
; Print the multi-line message
print_string message
; Terminate program
int 0x21
Summary:
By following these guidelines, students can effectively use emu8086.inc to simplify their
assembly programs in Emu8086.
LAB TASKS
1. Copy & paste the above programs to Emu8086 source code editor, and press
[Compile and Emulate] button. Run it!
2. Modify the above code to print your name on the screen. (Using print_string)
3. Modify the above codes to display a message showing more than one line on the
screen? (Using print_string)
4. Display the character ‘w’ on screen using putc?
5. Show 3 examples of use of gotoxy in combination with putc ?
6. Display the number 78 on screen using print_num?
7. Get a number from user using “scan num” and display it on screen using
“printnum” (without any messages for input and output by the help of nextline
ascii code)?