Debug
Debug
Modifying registers
-R CX:<enter>
CX 0000
:0009<enter>
-R CX<enter>
CX 0009
:<enter>
-
Debug
Assemble command – allows the programmer
to enter assembly language instructions into
memory.
-A 100<enter>
0B3C:0100 MOV AX,1<enter>
0B3C:0103 MOV BX,2<enter>
0B3C:0106 ADD AX,BX<enter>
0B3C:0108 INT 3<enter>
0B3C:0109<enter>
-
Debug
Unassemble command - allows the
programmer to display the machine code
in memory along with their assembly
language instructions.
-U 100 L1<enter>
0B3C:0100 B80100 MOV AX,1
-U 100 103
0B3C:0100 B80100 MOV AX,1
0B3C:0103 BB0200 MOV BX,2
-
Debug
Go command – allows the programmer
to execute instructions found between
two given addresses.
-G=100 108<enter>
AX=0004 BX=0003 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B3C ES=0B3C SS=0B3C CS=0B3C IP=0108 NV UP EI PL NZ NA PO NC
0B3C:0108 CC INT 3
Debug
Trace command - allows the programmer to
trace through the execution of a program one
or more instructions at a time to verify the
effect the program has on registers and/or
data.
-T=100 2<enter>
AX=0001 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B3C ES=0B3C SS=0B3C CS=0B3C IP=0103 NV UP EI PL NZ NA PO NC
0B3C:0103 BB0200 MOV BX,0002
-F 100 LF 00<enter>
-D 100 LF
0B3C:0100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …………….
-F 110 11F 20
-D 100 11F
0B3C:0100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …………….
0B3C:0110 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
-F 120 LF 20
-E 120 ‘John Smith’
-D 120 LF
0B3C:0120 4A 6F 68 6E 20 53 6E 69 74 68 20 20 20 20 20 20 John Smith
-
Debug
Loading programs from a specific file
requires two commands, the Name
command, N, and the Load command, L.
-N A:\PROG1.EXE
-L
C:\DEBUG A:\PROG1.EXE
Debug
Links to useful websites:
DEBUG/ASSEMBLY TUTORIAL by Fran
Golden
http://www.datainstitute.com/debug1.htm
Rough Guide to Assembly
http://www.geocities.com/riskyfriends/prog.
html
Paul Hsieh’s x86 Assembly Language
Page
http://www.azillionmonkeys.com/qed/asm.ht
ml
Assembly Language
Program
Series of statements which are either
assembly language instructions or
directives.
Instructions are statements like ADD
AX,BX which are translated into machine
code.
Directives or pseudo-instructions are
statements used by the programmer to
direct the assembler on how to proceed in
the assembly process.
Assembly Language
Program
Statement format:
[label:] mnemonic [operands][;comments]
Label:
Cannot exceed 31 characters.
Consists:
Alphabetic characters both upper and lower case.
Digits 0 through 9.
.MODEL SMALL
Ex:
MOV AH,0
MOV AL,7
INT 10H
BIOS Interrupt 10H
Option 2H – Sets the cursor to a specific location.
Registers used:
AH = 2H
BH = 0H selects Page 0.
DH = Row position.
DL = Column position.
Ex:
MOV AH,2
MOV BH,0
MOV DH,12
MOV DL,39
INT 10H
BIOS Interrupt 10H
Option 6H – Scroll window up. This
interrupt is also used to clear the screen
when you set AL = 0.
Registers used:
AH = 6H
AL = number of lines to scroll.
BH = display attribute.
CH = y coordinate of top left.
CL = x coordinate of top left.
DH = y coordinate of lower right.
DL = x coordinate of lower right.
BIOS Interrupt 10H
Clear Screen Example:
MOV AH,6
MOV AL,0
MOV BH,7
MOV CH,0
MOV CL,0
MOV DH,24
MOV DL,79
INT 10H
CS Code
DS Da ta
ES Ex tra
SS Sta ck
FS
Supple me nta l
GS
Effective, Segment and
Physical Addresses
Effective address (EA).
Alsocalled offset.
Result of an address computation.
Register relative.
Based indexed.
EA operand
PA DS 16 operand
Begin:
LEA EBX,DS:ARRAY
L1:
MOV EAX,DS:[EBX]
INC EBX
JMP L1
Begin:
MOV ESI,O
L1:
MOV EAX,DS:ARRAY[ESI]
INC ESI
JMP L1
Begin:
MOV ESI,O
L1:
MOV EAX,DS:ARRAY[ESI*4]
INC ESI
JMP L1
Alignment
It is best to align words with even
numbered addresses, and double words to
addresses divisible by four, but this is not
necessary.
The alignment allows for more efficient
memory access, but it is less flexible.
Immediate - Memory
When reading or writing to memory using
immediate addressing mode, the
programmer must specify the data size
otherwise the assembler will default to the
largest possible data size that processor
handles.
Use the following directives:
Byteptr.
Word ptr.
Dword ptr.
Other conditions
JE/JZ – Jump if equal
JNE/JNZ – Jump if not equal
JC – Jump if carry
JNC – Jump if not carry
JS – Jump if sign
JNS – Jump if not sign
Conditional Transfers
JO – Jump if overflow
JNO – Jump if not overflow
JP/JPE – Jump if parity/parity even
JNP/JPO – Jump if not parity/parity odd
These instructions conditionally modify the EIP
register to be one of two addresses defined as
follows:
An address or displacement following the instruction
(label);
The address of the instruction following the conditional
jump.
Ex:
JE SUM
SUB EAX,EBX
SUM:
Iteration Control
LOOP
LOOPE/LOOPZ
LOOPNE/LOOPNZ
The instructions listed above are used to
conditionally and unconditionally control
the number of iterations a program go
through a loop.
Operation of LOOP:
ECX ← ECX – 1
If ECX ≠ 0
then EIP ← EIP + displacement
Flags are not affected.
Iteration Control
Ex:
MOV ECX,2
Again: NOP
LOOP Again
What will happen if
MOV ECX,2
is replaced by
MOV ECX,0
in the code given above.
Iteration Control
Operation of LOOPE/LOOPZ:
ECX ← ECX – 1
If ZF = 1 and ECX ≠ 0
then EIP ← EIP + displacement
Flags are not affected.
Operation of LOOPNE/LOOPNZ:
ECX ← ECX – 1
If ZF = 0 and ECX ≠ 0
then EIP ← EIP + displacement
Flags are not affected.
Note that other instructions within the
loop have to change the condition of ZF.
Iteration Control
Ex:
MOV ECX,9
MOV ESI, -1
MOV AL, ‘D’
Again: INC ESI
CMP AL, LIST[EDI]
LOOP NE Again
JNZ NOT_FOUND
If DF=0 then:
Location Content
Re giste r SI 501H
Me mory loca tion 500H 'A'
Re giste r AL 'A'
Location Content
Re giste r SI 4FFH
Me mory loca tion 500H 'A'
Re giste r AL 'A'
STOS/STOSB/
STOSW/STOSD
Transfers the contents of the AL, AX or
EAX registers to the memory byte, word
or double word pointed to by DI relative
to ES. After the transfer is made, the DI
register is automatically updated as
follows:
DI is incremented if DF=0.
DI is decremented if DF=1.
STOS/STOSB/
STOSW/STOSD
Examples:
STOSB
ES:[DI]=AL; DI=DI 1
STOSW
ES:[DI]=AX; DI=DI 2
STOSD
ES:[DI]=EAX; DI=DI 4
STOS MEAN
ES:[DI]=AL; DI=DI 1 (if MEAN is a byte)
STOS LIST
ES:[DI]=AX; DI=DI 2 (if LIST is a word)
STOS MAX
ES:[DI]=EAX; DI=DI 4 (if MAX is a double word)
STOS/STOSB/
STOSW/STOSD
Example
Assume:
Location Content
Re giste r DI 500H
Me mory loca tion 500H 'A'
Re giste r AL '2'
If DF=0 then:
Location Content
Re giste r DI 501H
Me mory loca tion 500H '2'
Re giste r AL '2'
Location Content
Re giste r DI 4FFH
Me mory loca tion 500H '2'
Re giste r AL '2'
MOVS/MOVSB/
MOVSW/MOVSD
Transfers the contents of the the memory
byte, word or double word pointed to by SI
relative to DS to the memory byte, word or
double word pointed to by DI relative to
ES. After the transfer is made, the DI
register is automatically updated as
follows:
DI is incremented if DF=0.
DI is decremented if DF=1.
MOVS/MOVSB/
MOVSW/MOVSD
Examples:
MOVSB
ES:[DI]=DS:[SI]; DI=DI 1;SI=SI 1
MOVSW
ES:[DI]= DS:[SI]; DI=DI 2; SI=SI 2
MOVSD
ES:[DI]=DS:[SI]; DI=DI 4; SI=SI 4
MOVS MEAN
ES:[DI]=DS:[SI]; DI=DI 1; SI=SI 1 (if MEAN is a byte)
MOVS LIST
ES:[DI]=DS:[SI]; DI=DI 2; SI=SI 2 (if LIST is a word)
MOVS MAX
ES:[DI]=DS:[SI]; DI=DI 4; SI=SI 4 (if MAX is a double word)
MOVS/MOVSB/
MOVSW/MOVSD
Example
Assume:
Location Content
Re giste r SI 500H
Re giste r DI 600H
Me mory loca tion 500H '2'
Me mory loca tion 600H 'W '
If DF=0 then:
Location Content
Re giste r SI 501H
Re giste r DI 601H
Me mory loca tion 500H '2'
Me mory loca tion 600H '2'
Location Content
Re giste r SI 4FFH
Re giste r DI 5FFH
Me mory loca tion 500H '2'
Me mory loca tion 600H '2'
CMPS/CMPSB/
CMPSW/CMPSD
Compares the contents of the the memory
byte, word or double word pointed to by SI
relative to DS to the memory byte, word or
double word pointed to by DI relative to ES
and changes the flags accordingly. After
the comparison is made, the DI and SI
registers are automatically updated as
follows:
DI and SI are incremented if DF=0.
DI and SI are decremented if DF=1.
SCAS/SCASB/
SCASW/SCASD
Compares the contents of the AL, AX or
EAX register with the memory byte, word or
double word pointed to by DI relative to ES
and changes the flags accordingly. After
the comparison is made, the DI register is
automatically updated as follows:
DI is incremented if DF=0.
DI is decremented if DF=1.
REP/REPZ/REPNZ
These prefixes cause the string
instruction that follows them to be
repeated the number of times in the
count register ECX or until:
ZF=0 in the case of REPZ (repeat while
equal).
ZF=1 in the case of REPNZ (repeat
while not equal).
REP/REPZ/REPNZ
Use REPNE and SCASB to search for the
character ‘f’ in the buffer given below.
BUFFER DB ‘EE3751’
MOV AL,’f’
LEA DI,BUFFER
MOV ECX,6
CLD
REPNE SCASB
JE FOUND
REP/REPZ/REPNZ
Use REPNE and SCASB to search for the
character ‘3’ in the buffer given below.
BUFFER DB ‘EE3751’
MOV AL,’f’
LEA DI,BUFFER
MOV ECX,6
CLD
REPNE SCASB
JE FOUND
PC Parallel Printer Port
Types:
SPP – Standard Printer Port
PS/2 – Simple bidirectional
EPP – Enhanced Parallel Port
ECP – Extended Capabilities Port
Addressing:
Base addresses:
278H
378H
3BCH
Registers:
Data,8 bits, base address
Status, 5 bits, at base address + 1
Control, 6 bits, at base address + 2
PC Parallel Printer Port
Data Register (Base Address)
Inverted at
Bit Pin: DB-25 Signal Name I/O
connector?
0 2 Data bit 0 No Output
4 13 Select No Input
5 12 PaperEnd No Input
6 10 nAck No Input
2 16 Ninit No Output
DB-25 Connector
Connector 1 (Female) Connector 2 (Male)
13 <-------------------- 1 1 --------------------> 13
_____________________________ _____________________________
\ o o o o o o o o o o o o o / \ . . . . . . . . . . . . . /
\ o o o o o o o o o o o o / \ . . . . . . . . . . . . /
------------------------- -------------------------
25 <----------------- 14 14 ------------------> 25
DB-9 Connector
Connector 3 (Female) Connector 4 (Male)
5 4 3 2 1 1 2 3 4 5
_____________ _____________
\ o o o o o / \ . . . . . /
\ o o o o / \ . . . . /
--------- ---------
9 8 7 6 6 7 8 9
Each diagram shown above is the view you see when you look into the end of the cable.
Keyboard Interfacing
There are several types of keyboards
available for computer usage. Some of the
most common types are:
Mechanical switches
Membrane switches
Capacitive switches
Hall effect key switches
Most keyboards are organized as a matrix
of rows and columns. Getting data from
the keyboard requires the following steps:
Detecta key press.
Debounce the key press.
Encode the key.
Keyboard Interfacing
Keyboard Interfacing
Keyboard Interfacing
Keyboard Interfacing
Keyboard Interfacing
Encoding the key press:
Find the row and column positions
(obtained from the key detection routine).
Calculate the offset using the following
formula:
OFFSET = ( row * 8 ) + column
8 is the number of columns in the keyboard
matrix.
Find the proper character using the
offset, the base address of the
conversion table and XLATB instruction.
Interrupts
Interrupts/exceptions are actions prompting
the transfer of program execution to some
special routine.
Interrupt/exception Service Routine is the
routine executed as a result of an
interrupt/exception call.
Interrupts:
Maskable Interrupts (MI):
Do not occur unless interrupt flag is set.
STI – sets interrupt flag.
CLI – clears interrupt flag.
Non-Maskable Interrupt (NMI):
No mechanism is provided to prevent NMI’s.
Interrupts
Exceptions:
Some instructions may generate exceptions.
Example: DIV may generate the divide by zero
exception.
Interrupt Descriptor Table (IDT), also
known as Interrupt Vector Table, is a data
structure used for the purpose of handling
interrupts. They associate each
interrupt/exception with an address
indicating the location of the Interrupt
Service Routine which will be used to
service the calling interrupt.