18
Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal.

Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

Embed Size (px)

Citation preview

Page 1: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

Debug and Assembler

By,B.R.ChandavarkarLect. COMP DepartmentNITK, Surathkal.

Page 2: 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

Page 3: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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.

Page 4: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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

Page 5: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

• 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

Page 6: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

• 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

Page 7: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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.

Page 8: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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

Page 9: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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

Page 10: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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

Page 11: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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. 50Temperature DB ?. ?. ?. ?. ?Temperature DB 100 DUP(?)Temperature DB 10. 5 dup(55). 20Temperature DB 4 DUP( 3 DUP(5))Temperature DB “ABCD”

Page 12: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

• 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)

Page 13: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

• 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

Page 14: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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

Page 15: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

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

Page 16: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

Examples: ORG 0100HORG $ current value of addressORG $ + 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.

Page 17: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

MASM(Microsoft Macro Assembler)

• 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

Page 18: Debug and Assembler By, B.R.Chandavarkar Lect. COMP Department NITK, Surathkal

TASM(Turbo ASseMbler)

• 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