Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microprocessor and Assembly Language

Similar presentations


Presentation on theme: "Microprocessor and Assembly Language"— Presentation transcript:

1 Microprocessor and Assembly Language
Lecture-4-Introduction to Assembly Language Programming with Debug Utility Muhammad Hafeez Department of Computer Science GC University Lahore

2 Today’s Agenda Introduction to Assembly Language Programming
Debug Utility

3 .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

4 .COM and .EXE File

5 Assembly Language Instructions
Data Movement Instructions Arithmetic Instructions Logic Instructions Control Instructions

6 Data Movement Instructions
MOV Instruction XCHG Instruction

7 MOV Instruction Move Byte/ Word to Syntax is,
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

8 Legal Combinations of MOV Instruction
Destination Source General Register Segment Register Memory Location Constant Yes No

9 Legal Combinations of XCHG Instruction
Destination Source General Register Memory Location Yes No

10 Arithmetic Instructions
ADD Instruction SUB Instruction INC Instruction DEC Instruction

11 ADD & SUB Instructions ADD Syntax SUB Syntax ADD Source, Destination
SUB Source, Destination

12 Legal Combinations of ADD & SUB Instructions
Destination Source General Register Memory Location Yes No Constant

13 INC & DEC Instructions INC Syntax DEC Syntax INC Destination
DEC Destination INC add 1 to the destination DEC subtract 1 to the destination

14 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’

15 Examples: A = A -1 A = B A = B + 2*A B = B-1 Using Debug

16 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”

17 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

18 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 D U 0100 LD

19 Debug Utility G [Run a program till breakpoint]
G=start Address End Address G [press enter] G= D R [to see the Registers] T [Trace, to run a program step by step] T = Start Address # of instruction T [press Enter] T= [Run Two instructions] T 3 [only number of instructions, assume IP=0100]

20 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]

21 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 [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

22 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: E DS:0 ‘Adam Smith’ E CS:0100

23 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]

24 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 D U 0100 LD

25 Debug Utility D CS: D F Either Enter program through E E100 E 101 to put another char to print Or Assemble with A G to run the program U HEX numbers back to mnemonic codes See unassembled HEX numbers Stack first CS is loaded then IP is loaded

26 Debug Utility D CS: D F Either Enter program through E E100 E 101 to put another char to print Or Assemble with A G to run the program U HEX numbers back to mnemonic codes See unassembled HEX numbers Stack first CS is loaded then IP is loaded

27 Debug Utility R to manipulate Registers Rax to change AX register
Stack first CS is loaded then IP is loaded

28 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

29 Debug Utility - Summary

30 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

31 Questions ??????????????????????????


Download ppt "Microprocessor and Assembly Language"

Similar presentations


Ads by Google