Assembly Programming with DEBUG Guide
Assembly Programming with DEBUG Guide
C:\>DEBUG
-
Any loaded program is placed in memory in an appropriate segment. A displacement of 100H relative to
At the beginning of the segment, specify the starting address. It must be mentioned in the Debug.
C:\>DEBUG
-A 100
Debug selects an address for your program. It displays it and adds your offset.
Q1: What is the segment address chosen by your Debug?
For a segment address of 21CB and an offset of 100, the actual address of the first instruction of your
program is equal to (21CB0H + 100H).
Q2: What is the starting address of the program chosen by your Debug?
C:\>DEBUG
-A 100
21CB :0100 MOV DL,3F
21CB:0102 MOV AH,2
21CB:0104 INT 21H
21CB:0106 INT 20H
21CB:0108
The two instructions 'MOV AH,2' and 'INT 21H' allow the display of the character whose ASCII code is
stored in DL. To execute the program we do:
-G
?
Normal end of the program
-
- U 100 107
21CB :0100 B23F MOV DL,3F
21CB :0102 B402 MOV AH,2
21CB:0104 CD21 INT 21H
21CB:0106 CD20 INT 20H
To save the work done in a file [Link], we use the following commands:
-N [Link]
-R CX
CX 000
:8
-R BX
BX 000
:
-W
-Q
C:\>
The two registers CX and BX indicate the size of the program to be saved. In this case, it is 8 bytes.
starting from the departure address (100).
To run the program, you must type the name of the file:
C:\>TP1
?
C:\>
IV. Exercises
1. Write a program '[Link]' that displays all lowercase letters.
2. Write a program "[Link]" that displays all uppercase letters.
3. Write a program "[Link]" that displays all the digits from 0 to 9.
4. Disassemble the program "[Link]".
5. Display the status of the registers using the command
-R
6. Execute the program step by step using the command
-T
7. Restart the execution of the program using the command
- G 100
8. Launch the execution of a portion of the program using
-G=100 106
9. Perform a memory dump using the command
-D 100
10. Modify the memory address case "xxxx:0101"
-E 101
xxxx :0101 xx.41
11. Make a memory dump to view the BIOS date
D F000 :FFF0
12. Write a program that displays a message on the screen.
Objectives:
The objective of this manipulation is to familiarize the student with the environment of
NASMIDE assembler programming. We will use this tool to create programs.
advances based mainly on conditional and unconditional branch instructions.
Materials used:
A PC or compatible.
Software:
Microsoft Windows.
NASMIDE.
Duration:
3:00 AM
MedAli KAMMOUN Assembly programming with NASM
I. But of the TP
Familiarize yourself with the freeware assembler NAS associated with the NASMIDE syntax editor.
Check that the following options are configured in the menu options | directories
- Edit the program that displays a character A on the screen (the same as in TP 1). (Note, int 21
is now written as int 0x21 or int $21
- Press the F2 key to save the program.
- Press the keys alt + F9 simultaneously to assemble the program.
- An error window should normally indicate that no error has occurred.
100 Æ decimal
100h Æ hexadecimal
0x100 Æ hexadecimal as well
$100 Æ hexadecimal as well but the first character must be a digit
10000100b Æ binary
nb db $10
tab db 1, 2 ,3 ,4 ,5 ,6 ,7 ,8 ,10
message db Hello IUP GSI TI
(13Æ carriage return, 10Æ next line, $Æ end of string
R dd 1024
A dd 1.2
B dd 1.e10
C dd 1.e+10
D dq 1.e-10
pi dt 3.141592353589793238462
ÂIt is impossible to assign one variable directly to another variable; it is mandatory to go through
by a register.
ÂIt is also impossible to assign a constant directly to a variable; it is also necessary to pass.
by a register.
Example:
III. Exercises
Exercise 1:
1) Create the flowchart of the program that calculates the sum of the first 11 integers.
(0 + 1 + 2 +... + 10 + 11). Then write the program in 8086 assembly. We will use the instruction for this.
MOV, CMP, JNE, ADD, DEC or INC... We will use a variable R to store the result and a variable N.
to store the number 11.
2) Then display the result on the screen using interrupt $21 and deduce based on the character
display the numerical value of the result.
The interruption with 21 at 9 allows displaying character strings that end with character 13, 10
$13Æ return carriage, 10Æ next line, $Æ end of string
To do this, you need to define a message with the pseudo instruction db (see db explanations) by ending this
message by 13, 10, '$'.
Then you need to assign the address of this message to registedxl (mov dx, mess where mess is the name given to)
message).
Write a program that displays the following message ten times on the screen with a line break and a newline:
If I do well in lab work, I will become a god of assembly and the teacher will be proud of me.
Exercise 3:
Design an application that calculates the product of two numbers A = 100 and B = 170. The numbers A and B are
coded on 8 bits each.
• What instruction should be used?
• Where are the operands?
• Where is the result of the operation.
• Display the bytes of the register containing the result of the operation.
• Deduce the numerical result from the displayed characters.
Mêmes questions mais avec des nombres A et B de 16 bits. PrendreA = 1642etB = 10.
Try with A=3227 and B=5.
How does the result appear?
How to make printable characters always appear?
Objectifs :
The objective of this lab is to introduce the principles of manipulating complex data.
through advanced assembler programs. For this, NASMIDE will be used as
tool for creating some programs based on the principle of addressing 'based
indexed." This principle will be used to manipulate the elements of arrays and strings.
characters. At the end of this process, the student will have to translate a sorting algorithm that
we will apply to a string.
Materials used:
A PC or compatible.
Software:
Microsoft Windows.
NASMIDE.
Durée :
1erapart: 3H00mn
2thpart: 1H30mn
Med Ali KAMMOUN Assembly programming with NASM: addressing
II. Reminders
To address the various elements of an array, indexed addressing must be used based on taking the register.
BX as base and DI or SI as index. To set the base of the table (table displacement)
in the data segment) in BX, just write:
MOV BX, name of the array.
Then, indexed-based addressing is used in the following way:
MOVE AL, [BX+SI] put the SIemearray element in the AL register
Where represents the position of the element in the array that we want to reach.
[Link]
Exercise 1:
Here is the following table:
tab db 5, 30, 20, 1,11, 8
Sum the 6 elements of this array and put the result in a variable S. Display the result.
the screen, deduce the numerical value.
Exercise 2:
Write an application that counts the number of letter 'e' in any sentence (minimum 50 characters)
ending with the character '$'.
Represent the organization chart.
Put the result in the register and add 32.
Print the character on the screen and check if the character that appears is consistent
Exercise 3:
Define a string of at least 50 characters ending with '$'.
Create an application (flowchart + program) that replaces all letters of a given type with a
another type (for example all 'e' by 'a').
We will enter the two letters from the keyboard using interrupt 21,8.
Key inputs will be preceded by a message of the type 'Replace:' and 'by:'
IÅ0
jÅ1
nÅ5
while i < n-1
while j < n
If tab[i] > tab[j] then Swap(tab, i, j)
j=j+1
as long as
i=i+1
j=i+1
as long as
Apply the following algorithm to the table filling in the following state table:
the aim of this problem is to sort this string of characters in ascending order of ASCII code
Write the program that sorts the previous string in ascending order of ASCII code.
We will take SI for index i and DI for index j.
We will display the result using interrupt $21, 9.
Objectives:
The objective of this manipulation is to present the principles of graphical programming.
using assembly language. At the end of this manipulation, the student will be able to
produce complex geometric shapes by directly manipulating video memory,
by programs in assembly language.
Materials used:
A PC or compatible.
Software:
Microsoft Windows.
NASMIDE.
Duration:
6:00 am
MedAli KAMMOUN Graphical assembly programming in MCGA mode
320
0 1 2 3 4 5 6 7 318 319
. . . . . . .
. . . . . . .
320 321
200
To return to text mode at the end of the program, we will use mode 0x03.
-ahÅ 0
-alÅ 0x03
Interrupt call 0x10
Example:
you
move bx, 160
move [es:bx + 320], dl ; we write to the address 0xa000 + 160 +320
you
you
[Link]
Exercise 1:
Turn on the pixel at coordinates (200,100) with color code 0x32.
Turn on the first 256 pixels, assigning them a color varying from 0 to 255.
Same question but increasing the thickness of the line (5 lines).
Same question but regarding the entire height of the screen (see following figure).
Exercise 2:
Surround the screen with a frame 5 pixels thick in the color of your choice.
Grid the screen with a line of 5 pixels thick and a spacing of 10 pixels between the lines.
The key press test will be performed using interrupt 0x16 (see appendix)
The variables to be used will be as follows:
Between each display, it is necessary (at least on Pentiums) to generate a delay. For this,
we will write a simple timer subprogram of the type:
To move the pattern to the left or right, we will use a delta variable that will take the value 1.
according to the direction of movement. This variable will serve as an increment to display the next position of the
motive.
It will be necessary to test if we reach the upper right limit (320-L) to give delta the value -1 and
test the lower left limit (0) to set delta to +1.
Rq:
Objectives:
The aim of this manipulation is to introduce the principles of programming.
assembler according to TASM syntax. For this, we will use Turbo-ASM from Borland as
tool for creating some simple programs.
Materials used:
A PC or compatible.
Software:
Microsoft Windows.
- TASM.
Duration:
3:00 AM
MedAli KAMMOUN Assembly programming with TASM
TITLE nom_programme
Pile ENDS
DATA SEGMENT
DATA ENDS
CODE SEGMENT
DebutCode:
CODE ENDS
END DebutCode
Example:
;***********************************
;* A F I C H A I N . A S M *
;****************************TA 2.0*
AFICHAIN
Pile ENDS
Data SEGMENT
Data ENDS
CODE SEGMENT
ASSUME DS:Data, CS:CODE
DebutCode:
move bx,Data
move ds,bx set DS to point to the .DATA segment
move dx,OFFSET DataString
;make DX point to the displacement of
DataString in the .DATA segment
move ah,9 ;function to display DOS string
int 9 PM function call
move ah,4ch program deactivation function
;the DOS
int 9 PM call of the DOS
CODE ENDS
END DebutCode
[Link]
Exercise 1:
Draw the flowchart of a program that displays the message 'Hello everyone' on the screen.
the organizational chart in the program and check its proper functioning.
Modify the previous program to display the same message 10 times. Start by listing
the organizational chart.
Exercise 2:
- Dressez l ’organigramme d ’un programme qui vous pose la question : « Somme-nous l ’après midi ? » (O/N). Si
if you type 'O' it shows you 'Good afternoon', otherwise it shows you 'Hello'.
Translate the flowchart into assembly program under TASM.
Exercise 3:
Draw the flowchart of a program that reads a lowercase character from the keyboard and converts it into
uppercase.
Transform the organizational chart into a program under TASM.
Exercise 4:
‘* *’
** **
*** ***
********
The use of a loop is mandatory.
Transform the organizational chart into a program under TASM.
Objectives:
The objective of this manipulation is to present to the student the principles of the
programming of the 8255 parallel interface. The experiment focuses on a parallel port
implemented on the MTS-86C Kit and is controlled by an 8255. The student's role is to
manipulate this port by writing assembly codes to control diodes
you can receive information from push buttons.
Materials used:
The MTS-86C Kit.
A PC or compatible device equipped with a serial communication port.
Logiciels :
Microsoft Windows
Hyper Terminal
Duration:
1eraétape : 3H00mn
MedAli KAMMOUN Assembly programming of an Input/Output interface: the i8255
The purpose of this manipulation is to become familiar with the use of the parallel communication interface.
8255 integrated into the MTS-86C system.
II. Presentation
The exchanges between the microprocessor and its external environment (keyboard, screen, printer,…) occur at
the help of interface circuits often called 'Input/Output couplers'. These exchanges can be carried out
in parallel or in series.
As part of this operation, we will use a coupler for parallel connection from the 8200 family.
Intel: this is the PPI (Programmable Peripheral Interface) 8255.
[Link] 8255
The Intel 8255 is a programmable input/output interface designed for use with microprocessors.
Intel. It has 24 programmable input/output pins organized into two groups of 12 pins each and it can be
used in 3 modes.
In the first mode (MODE 0), each group of 12 pins can be programmed in batches of 4 pins as input.
or output. In (MODE 1), the second mode, each group can be programmed so that 8 lines
can be configured as inputs or outputs. The third mode, (MODE 2), is a bidirectional mode where 8
Lines are used as a bidirectional bus.
__
CS
This pin, active in the low state, allows communication between the 8255 and the CPU.
__
RD
This pin, active in the low state, allows the 8255 to transfer data or configuration information.
to the CPU via the data bus.
__
WR
This pin, active in the low state, allows the microprocessor to send data or the Control Words to the
8255.
A0and A1
These input pins, combined with the WR and RD pins, control the selection of the ports (A, B, or C) or the
Control Word register.
__ __ __
A1 A0 WR CS Input Operations (Read)
RD
0 0 0 1 0 Port A->Data Bus
0 1 0 1 0 Port B->Data Bus
1 0 0 1 0 Port C->Data Bus
Output Operations (Write)
0 0 1 0 0 Data Bus -> Port A
0 1 1 0 0 Data Bus -> Port B
1 0 1 0 0 Data Bus -> Port C
1 1 1 0 0 Data Bus -> Control
Deactivation functions
x x x x 1 Data Bus -> 3 states
1 1 0 1 0 Illegal condition
x x 1 1 0 Data Bus -> 3 states
IV. Manipulation
The MTS-86C system has 3 programmable parallel interfaces 8255. The interface number 3 (PPI-3) is used
for experimentation and it is connected to the diodes and the SW buttons according to the electronic diagrams
available in the appendix.
According to these diagrams, port A is connected to the buttons SW and port B is connected to the diodes via the
74LS240 circuits.
Suppose we want to write a program in assembly that allows us to turn on the LED diode.
pressing the corresponding SW button.
The program is then written as follows:
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 0
CODE ENDS
END START
Test the proper functioning of the previous program on the MTS-86C board.
Annex
ASCII Table (7-bit)