440 likes | 1.77k Views
Debug and Assembler. By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal. Debug. Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program, thus making it behave as expected.
E N D
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.
Debug • Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program, thus making it behave as expected. • It is program which allows the programmer to write , execute and debug assembly language programs, and to examine the content of registers and memory. It can also be used to run a program one instruction at a time. • To start DEBUG its name is typed after DOS prompt. i.e. c:\> DEBUG
Debug Commands • It has a number of commands to facilitate users to write, execute and debug programs. • A DEBUG command is represented by a one-letter symbol. • DEBUG commands are not case-sensitive.
A – Assemble Command.: It allows user to enter assembly language program and converts it into machine codes. Syntax: A [offset-address] • U – Unassemble Command : It disassembles machine codes of specified memory addresses and gives corresponding mnemonics. Syntax: U [address-range] • R – Register Command : Used to display the contents of one or more registers. It also display the status of the flags. Syntax: R [register name] • G – Go Command : It is used to execute a program. Syntax: G [= address] • T – Trace Command : It is used to run a program in single-step mode. Syntax: T = address [step]
D – Display or Dump Command : It is used to display the contents of specified memory locations. Syntax: D address-range or D address • E – Enter Command : It is used to enter the data or machine code. Its default register is the DS. Syntax: E address • F – Fill Command : It is used to fill the specified range of locations with the values given in a list. Syntax: F address-range values • M – Move Command : It copies the block of data from one memory area to another. Syntax: M range address
S – Search Command :It is used to search the specified memory range for the specified list of bytes. The default register is the DS. Syntax: S range list • N – Save Command : It is used to save a file. Syntax: N filename.com • W – Write Command • L – Load Command • Q – Quit Command
Assembler • An assembler is a computer program for translating assembly language — essentially, a mnemonic representation of machine language — into object code • It is program which allows the programmer to write , execute and debug assembly language programs, and to examine the content of registers and memory. It can also be used to run a program one instruction at a time. • It is more powerful and provides more facilities as compared to DEBUG.
Self-Assembler or Resident-Assembler : It runs on a computer for which it produces object codes. • Cross-Assembler : It runs on a computer other than that for which it produces object codes. • Macro-Assembler : Which allows the user to define sequence of instructions as macro. • Meta-Assembler : Which can handle different instruction sets. • Disassembler : Which generates assembly Language Program corresponding to an object program. • One-Pass Assembler : Which goes through an ALP only once and produces its object codes. • Two-Pass Assembler : Which goes through an ALP only twice and produces its object codes.
An ALP contains two types of statements : Instructions : These are translated into machine codes. Directives : These are not translated into machine codes. It gives the direction to the assembler to perform the task of assembly process. The assembler supports directives for data definition, segment organization, procedures, macro definition, etc. • Examples : MASM(Microsoft ASseMbler), TASM(Turbo ASseMbler), FASM(FlatASseMbler), NASM(Netwide ASseMbler), etc.
Symbols, Variables and Constants : * The following characters are used for symbols: A to Z, a to z, 0 to 9, _, @, $, ? * The following characters are used for variables: A to Z, a to z, 0 to 9, _, @. The digits are not used as a first character of a variable name. Maximum Length of a variable is up to 32 characters. The letters B, D and H are written at the end of a binary, decimal and hexadecimal number respectively.
Directives • DB – Define Byte : It defines a byte type variable. It direct the assembler to reserve one byte of memory and initialize that byte with the specified value. It can define single or multiple variables. Examples: Temperature DB 10 Temperature DB ? Temperature DB 10. 20. 30. 40. 50 Temperature DB ?. ?. ?. ?. ? Temperature DB 100 DUP(?) Temperature DB 10. 5 dup(55). 20 Temperature DB 4 DUP( 3 DUP(5)) Temperature DB “ABCD”
DW – Define Word : It defines a word type variable. It direct the assembler to reserve two byte of memory and initialize those bytes with the specified value. It can define single or multiple variables. Examples : Temperature DW 1234H Temperature DW 1234. 5678. 1456 Temperature DW 2 DUP(0)
DD – Define Double Word : It defines a double word(4 bytes) type variable. It direct the assembler to reserve four byte of memory and initialize those bytes with the specified value. It can define single or multiple variables. Examples : Temperature DD 12345678 Temperature DD 5 DUP(0) • DQ – Define Quad Word : It defines a quad word(8 bytes) type variable. It direct the assembler to reserve eight byte of memory and initialize those bytes with the specified value. It can define single or multiple variables. Examples : Temperature DQ 12345678 Temperature DQ 5 DUP(0) • DT – Define Ten Bytes
EXTRN – External : It tells the assembler that names or labels following the directive are in some other assembly module. Examples: EXTERN Temperature : word EXTERN Temperature : far • PUBLIC : It informs the assembler that the defined name or label can be accessed from other program modules. Examples: PUBLIC Temperature1, Temperature2 • GLOBAL : • SEGMENT : It indicate the beginning of a logical segment. Syntax: segment name SEGMENT [word/public]
ENDS : It informs the assembler the end of the segment. Syntax: segment name ENDS • ENDP : It indicate the end of procedure. Syntax: procedure name ENDP • END : It indicate the end of the program. • ASSUME : This tells the assembler the name of a logical segment, which is to be used for a specified segment. Examples: ASSUME CS:code; DS:data • EQU : It assign name to some value. Examples: Temp EQU 04H • ORG : It tells the assembler to assign addresses to data items or instruction in a program.
Examples: ORG 0100H ORG $ current value of address ORG $ + 30 • SRUCT or STRUC :It is used to define the start of a data structure. • PTR : It is an operator. It points the type of memory access. Examples: mov byte ptr [bx], 58h • LENGTH : It tells the assembler to determine the number of elements in a specified variable. Examples: mov cx, length arry1 • SIZE : It gives the number of byte allocated to data item. • OFFSET : It determines the offset.
MASM(MicrosoftMacroAssembler) • The Microsoft Macro Assembler (abbreviated MASM) is an assembler for the x86 family of microprocessors. It was originally produced by Microsoft for development work on their MS-DOS operating system, and was for some time the most popular assembler available for that operating system. • Steps to work on MASM: * c:\masm> edit [filename.asm] * Save file with filename.asm * c:\masm> masm filename.asm * c:\masm> link filename + io * c:\masm> filename
TASM(TurboASseMbler) • The Turbo Assembler (TASM) mainly PC-targeted assembler package. • TASM worked well with Borland's high-level language compilers for the PC, such as Turbo C and Turbo Pascal. • Steps to work on TASM: * c:\tasm> edit [filename.asm] * Save file with filename.asm * c:\tasm> tasm filename.asm * c:\tasm> tlink filename + io * c:\tasm> td filename