Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

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 Segment Memory Constant
Register Register Location
General Yes Yes Yes No
Register
Segment Yes No Yes No
Register
Memory Yes Yes No No
Location
Constant Yes No Yes No
LEGAL COMBINATIONS OF
XCHG INSTRUCTION
Destination
Source General Register Memory Location
General Yes Yes
Register

Memory Yes No
Location
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 Yes Yes
Register

Memory Yes No
Location

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 -1
 A = B
 A = B + 2*A
 B = B-1

 Using Debug
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
 R AX
 A Start Address [Assemble the Code]
 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 AH,FF3
 MOV AX,12345
 MOV DS,1240
 MOV SI,DH
 MOV BX,AH
 MOV 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
 R AX
 A Start Address [Assemble the Code]
 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
 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
 -W
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

 ??????????????????????????

You might also like