1 / 29

Objectives

Chapter 3 - 8086 family assembly language programming - introduction from Microprocessors and Interfacing by Douglas Hall. Objectives. At the end of this chapter you will learn: Write a task list, flow chart or pseudo code for simple programming problem.

race
Download Presentation

Objectives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 - 8086 family assembly language programming - introduction from Microprocessors and Interfacing by Douglas Hall

  2. Objectives • At the end of this chapter you will learn: • Write a task list, flow chart or pseudo code for simple programming problem. • Write code, assemble and run a very simple assembly language program. • Describe the use of program development tools such as editors, assemblers, linkers, locators, debuggers and emulators. • Properly document assembly language programs

  3. Outline • Program Development Steps • Representing program operations • Finding the right instructions • Writing a program • Constructing the machine codes for 8086 instructions • Instruction templates • MOD and R/M Bit patterns in 8086 • Tips for hand coding • Writing programs for the use with assemblers • Program format • Assembler Directives • Types of numbers used in data statements • Assembly Language Program development Tools

  4. Program Development Steps • The problem that you want to solve • Just ask yourself question that “What do I really want this program to do?”

  5. Representing program operations • Formula or sequence of operations used to solve a programming problem is called as the algorithm. • There are two ways of representing algorithms: • Flowchart • Structured programming and pseudo code

  6. Flowchart • It uses graphical shapes to represent different types of programming operations. • Flow chart symbols

  7. Structured programming and pseudo code • Programs should be understandable to other programmers • Two approaches top-down and bottom up approach • Top-down: divide the program in to major modules and divide theses major modules in to sub modules and so on. • Bottom-up: each programmer writes the low level module code and hopes that all pieces will eventually fit together. • Use set of three to seven standard structures. • Main structures are only three viz. IF-THEN-ELSE, SEQUENCE & WHILE-DO. • The others are IF-THEN, CASE & REPEAT-UNTIL.

  8. Finding the right instructions • Instructions in 8086 are mainly divided into following categories • Data Transfer Instructions • Arithmetic Instruction • Bit manipulation Instruction • String Instruction • Program execution transfer Instruction • Processor control Instruction

  9. Writing a program • You need to do the following to write the program effectively: • INITIALIZATION INSTRUCTIONS: used to initialize various parts of the program like segment registers, flags and programmable port devices. • STANDARD PROGRAM FORMAT: it’s a tabular format containing ADDRESS, DATA OR CODE, LABELS, MNEM, OPERAND(S) and COMMENTS as the columns. • DOCUMENTATION: you should document the program. E.g. each page of the document contains page number and name of the program, heading block containing the abstract about the program, comments should be added wherever necessary.

  10. Constructing the machine codes for 8086 instructions • Each instruction in 8086 is associated with the binary code. • You need to locate the codes appropriately. • Most of the time this work will be done by assembler • The things needed to keep in mind is: • Instruction templates and coding formats • MOD and R/M Bit patterns for particular instruction

  11. Instruction template • The Intel literature shows two different formats for coding 8086 instructions. • Instruction templates helps you to code the instruction properly. Coding Template for 8086 IN Instruction

  12. MOD and R/M Bit patterns in 8086 (contd.)

  13. MOD and R/M Bit patterns in 8086 - Use • If the other operand in the instruction is also one of the eight register then put in 11 for MOD bits in the instruction code. • If the other operand is memory location, there are 24 ways of specifying how the execution unit should compute the effective address of the operand in the main memory. • If the effective address specified in the instruction contains displacement less than 256 along with the reference to the contents of the register then put in 01 as the MOD bits. • If the expression for the effective address contains a displacement which is too large to fit in 8 bits then out in 10 in MOD bits.

  14. MOV instruction coding format(contd.) • MOV SP, BX: this instruction will copy a word from BX register to SP register.

  15. MOV instruction coding format(contd.) • MOV 43H [SI], DH: copy a byte from DH register to memory location.

  16. MOV instruction coding format • MOV CX, [437AH]: copy the contents of the two memory locations to the register CX.

  17. Tips for Hand Coding 8086 Programs • Check your algorithm very carefully to make sure that it really does what it supposed to do. • Initially write down assembly language statements and comments for your program. • Recheck each statement to make sure that you have right instructions to implement your algorithm. • Finally work out the binary code needed by each instruction and execute you program.

  18. Writing programs for use with and assembler • Allows you to refer the data items by names rather than their offsets. • How to write the programs so that it can be used by the assemblers.

  19. Program Format • There are assembler level directives available to the programmer so that he can write programs which are compatible with the assembler. Sample formatted program 

  20. Assembler Directives(contd.) • There are different directives available for assembler each with their unique purpose. • SEGMENT and ENDS Directives • Naming data and Addresses – EQU, DB, DW and DD Directives • The ASSUME Directive • The END Directive

  21. Assembler Directives(contd.) • SEGMENT and ENDS Directive: • The SEGMENT and ENDS directives are used to identify a group of data items or group of instructions that you want to be put together in a particular segment. • A logical segment is not usually given starting address when it is declared. • EQU Directive: used to assign names to constants. • DB, DW and DD Directives: used to assign names to variables.

  22. Assembler Directives(contd.) • The ASSUME Directive • 4 physical segments: code, data, stack and extra segment • tells which logical segment to use for each of the physical segment at a given time. • The END Directive • Tells the assembler to stop reading • instruction or statements that are written after END will be ignored.

  23. Assembly Language Program Development Tools • There are several tools available to support the programmer of assembly language for better experience of programming. They are discussed in brief here: • Editor • Assembler • Linker • Locators • Debuggers • Emulators

  24. Editor • It is the program which allows you to create a file containing the assembly language statements for your program. • Examples are PC Write, Word stars and the editors that comes with assemblers. • Creates Source file to be processed by the assembler

  25. Assembler • It is the program which is used to transfer the assembly language mnemonics to corresponding binary codes. It works in passes. • In the first pass, it determines the displacement of the named data items, the offset of labels etc. and puts this information to in a symbol table. • In the second pass, it produces the binary codes for each instructions and inserts the offsets etc. that it calculated in the first pass. • It generates two files namely object file (.OBJ) and assembler list file (.LST).

  26. Linker • It is a program used to join several object files into large object files. • While writing large programs it is good to divide them into modules so that each modules can be written, tested, debugged independently and then use linker to combine the modules to form the actual program. • It produces two files link file which contains the binary codes of all the combined modules and a link map file which contains the address information about the linked files.

  27. Locators • A locator is the program used to assign the specific addresses of where the segments of object code are to be loaded in to main memory. • Examples include EXE2BIN which comes with the IBM PC DOS. • Converts .exe to .bin files which has physical addresses

  28. Debugger • A debugger is the program which allows you to load your object code program in to system memory. • It allows you to look at the contents of the registers and memory locations after your program runs. • It also allows you to set breakpoints at any points in the program. • It simply allows you to find the source of the problem into the program. • There are lots of debuggers available like Borland Turbo Debugger, Microsoft’s Code view debugger etc.

  29. Emulators • One way to run your program • It is mixture of hardware and software. • Generally used to test the hardware and software of an external system such as microprocessor based instruments. Applied Microsystems ES 1800 16-bit emulator 

More Related