Download MPAL-Lecture-04

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
MICROPROCESSOR AND
ASSEMBLY LANGUAGE
LECTURE-4-INTRODUCTION TO ASSEMBLY
LANGUAGE PROGRAMMING WITH DEBUG
UTILITY
MUHAMMAD HAFEEZ
DEPARTMENT OF COMPUTER SCIENCE
GC UNIVERSITY LAHORE
TODAY’S AGENDA


Introduction to Assembly Language
Programming
Debug Utility
.COM AND .EXE FILE


DOS allows two types of executable
in its command shell
.COM --- Max. Program Size 64K


Directly converted into binary
If a .com file takes 10 bytes, actual size
of file will be 10 bytes

Debug deals with .COM


Same Value in SS, DS, ES and SS
.EXE ---- Max. Program Size all
available memory

Minimum Size 640 Bytes
.COM AND .EXE FILE
ASSEMBLY LANGUAGE
INSTRUCTIONS




Data Movement Instructions
Arithmetic Instructions
Logic Instructions
Control Instructions
DATA MOVEMENT INSTRUCTIONS


MOV Instruction
XCHG Instruction
MOV INSTRUCTION

Move Byte/ Word to






Register-to-Register
Register-to-Memory
Memory-to-Register
Immediate [common error is trying to move larger
constants than destination size]
Syntax is,
Size of the operands must be same

MOV Destination, Source



Source is from where we pick data
Destination is where we put data
CS and IP must never be destination
LEGAL COMBINATIONS OF MOV
INSTRUCTION
Destination
Source
General
Register
Segment Memory
Register Location
Constant
General
Register
Yes
Yes
Yes
No
Segment Yes
Register
No
Yes
No
Memory
Location
Yes
No
No
No
Yes
No
Yes
Constant Yes
LEGAL COMBINATIONS OF XCHG
INSTRUCTION
Destination
Source
General Register
Memory Location
General
Register
Yes
Yes
Memory
Location
Yes
No
ARITHMETIC INSTRUCTIONS




ADD Instruction
SUB Instruction
INC Instruction
DEC Instruction
ADD & SUB INSTRUCTIONS

ADD Syntax


ADD Source, Destination
SUB Syntax

SUB Source, Destination
LEGAL COMBINATIONS OF ADD
& SUB INSTRUCTIONS
Destination
Source
General Register
Memory Location
General
Register
Yes
Yes
Memory
Location
Yes
No
Constant
Yes
Yes
INC & DEC INSTRUCTIONS

INC Syntax


INC Destination
DEC Syntax



DEC Destination
INC add 1 to the destination
DEC subtract 1 to the destination
NEG INSTRUCTIONS

NEG instruction negate the contents of
memory or Register


Does this my taking 2’s complement of content
NEG Syntax


DEC Destination
NOTE: In all the Instructions Size/ Type of
Operands must be same, however, assembler
accepts MOV al,’C’ and MOV ax,’C’
EXAMPLES:

A
A
A
B

Using Debug



=
=
=
=
A -1
B
B + 2*A
B-1
INSTALL DOSBOX


DOSBox is an Emulator which emulate old
8086/88 and 80286/386 environment on
your current i3/i5/i7 processor.
Follow the steps given in online post
”Installing MASM on Windows 7”
DEBUG UTILITY



A debugger displays the content of memory
quickly and easily, showing registers and
variables.
You can step through a program one line at
a time (called tracing).
Some debugging functions are:







Assemble short program
View a program’s source code, along with its machine code
View the CPU registers and flags
Trace or execute a program, watching variables for changes
Enter new values in memory
Fill a block of memory
load and write disk files
DEBUG UTILITY




Debug assume all the numbers in HEX
C:\Masm>Debug [Press Enter]
R [to see the Registers]
R Register name to change the content


A Start Address [Assemble the Code]



R AX
A 0100
U Start Address End Address
U Start Address L #of bytes


U 0100 010D
U 0100 LD
DEBUG UTILITY


G [Run a program till breakpoint]
G=start Address End Address





G [press enter]
G=0100 010D
R [to see the Registers]
T [Trace, to run a program step by step]
T = Start Address # of instruction



T [press Enter]
T=0100 2 [Run Two instructions]
T 3 [only number of instructions, assume
IP=0100]
DEBUG UTILITY

Common Errors with Register Usage






MOV
MOV
MOV
MOV
MOV
MOV
AH,FF3
AX,12345
DS,1240
SI,DH
BX,AH
AL,CX
[Errors]
DATA MANIPULATION IN DEBUG
UTILITY



F [fill the block of memory with data]
F [start address] [end address] [data]
F [start address] [L no of bytes] [data]





F 0 10 FF
F 0 LD EF
F 0 20 20 41 [alternate pattern]
D [Dump command, examine the content
of memory]
D [start address] [end address]
D [start address] [L no. of bytes]

Variation of D
DATA MANIPULATION IN DEBUG
UTILITY


D [dump will be shown from DS:0100 to
128 bytes]
D offset [D will assume DS as segment]





Fill and look up the Dump
Enter Command and Use Dump to examine
machine code
E [Enter Data with E command]
E [start address] data
E Start Address



E DS:0 41 42 43 44
E DS:0 ‘Adam Smith’
E CS:0100
DATA MANIPULATION IN DEBUG
UTILITY

Alter data using E






E 106 [press enter]
P [Procedure], used to execute procedure
P [start address] [no. of instructions]
M [start address], [end address] [dest.
Address]
C , Check block of memory for difference
C [start address] [end address] [compare
address]
DEBUG UTILITY




Debug assume all the numbers in HEX
C:\Masm>Debug [Press Enter]
R [to see the Registers]
R Register name to change the content


A Start Address [Assemble the Code]



R AX
A 0100
U Start Address End Address
U Start Address L #of bytes


U 0100 010D
U 0100 LD
DEBUG UTILITY









D CS:0100 110
D 100 110
F 100 110
Either Enter program through E
E100
E 101 to put another char to print
Or Assemble with A
G to run the program
U 100 106



HEX numbers back to mnemonic codes
See unassembled HEX numbers
Stack first CS is loaded then IP is loaded
DEBUG UTILITY









D CS:0100 110
D 100 110
F 100 110
Either Enter program through E
E100
E 101 to put another char to print
Or Assemble with A
G to run the program
U 100 106



HEX numbers back to mnemonic codes
See unassembled HEX numbers
Stack first CS is loaded then IP is loaded
DEBUG UTILITY

R to manipulate Registers
Rax to change AX register

Stack first CS is loaded then IP is loaded

DEBUG UTILITY


Save program on disk from debug utility
Three step process


-Nfilename.com Name of the File
How many bytes the program has taken

CX, BX register will be used to hold bytes to save



-W
CX lower order of this number, BX high order of this number
Use only CX register to hold number of bytes, put no of bytes
in CX
DEBUG UTILITY - SUMMARY
LITTLE ENDIAN AND BIG ENDIAN

If low byte is stored at lower memory
address called little endian


Used in INTEL processors
If low byte is stored at high memory
address called big endian

Used in Motorola processors
QUESTIONS

??????????????????????????