Presentation is loading. Please wait.

Presentation is loading. Please wait.

7-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Introduction to Assembly.

Similar presentations


Presentation on theme: "7-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Introduction to Assembly."— Presentation transcript:

1 7-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Introduction to Assembly Language Programming

2 7-2 Overview of Assembly Language  Advantages:  Disadvantages: Faster as compared to programs written using high-level languages Efficient memory usage Control down to bit level  Need to know detail hardware implementation  Not portable  Slow to development and difficult to debug  Basic components in assembly Language: Instruction, Directive, Label, and Comment

3 7-3 Example of Assembly Language Program ;NUMOFF.ASM: Turn NUM-LOCK indicator off..MODEL SMALL.STACK.CODE.STARTUP MOV AX,40H ;set AX to 0040H D1: MOV DS,AX ;load data segment with 0040H MOV SI,17H ;load SI with 0017H AND BYTE PTR [SI],0DFH ;clear NUM-LOCK bit.EXIT END Comments Assembly directive Instructions Assembly directive Label

4 7-4 Instruction Format  General Format of Instructions Label: Opcode Operands ; Comment  Label: It is optional. It provides a symbolic address that can be used in branch instructions  Opcode: It specifies the type of instructions  Operands: Instructions of 80x86 family can have one, two, or zero operand  Comments: Only for programmers’ reference  Machine Code Format OpcodeOperand1ModeOperand2 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 1 MOV AL, BL MOV Register mode

5 7-5 DATA SEGMENT PARA 'DATA‘ ORG 7000H POINTS DB 16 DUP(?) SUM DB ? DATA ENDS CODE SEGMENT PARA 'CODE‘ ASSUME CS:CODE, DS:DATA ORG 8000H TOTAL: MOV AX,7000H MOV DS,AX MOV AL,0 CODE ENDS END TOTAL 0000 DATA SEGMENT PARA 'DATA’ ORG 7000H 7000 0010 [00] POINTS DB 16 DUP(?) 7010 00 SUM DB ? 7011 DATA ENDS 0000 CODE SEGMENT PARA 'CODE' ASSUME CS:CODE, DS:DATA ORG 8000H 8000 B8 7000 TOTAL: MOV AX,7000H 8003 8E D8 MOV DS,AX 8005 B0 00 MOV AL,0  Source File  List File Assembler Directives

6 7-6 Assembler Directives  SEGMENT directive  ENDS directive  END directive  ORG directive  DB: Define Byte; DW, ….  ASSUME directive — Specifies the segment register (segment Register) that will be used to calculate the effective addresses for all labels and variables defined under a given segment or group name (segment Name). If CS = 1230H and DS = 5678H, what are the physical memory addresses of label TOTAL and variable SUM?

7 7-7 Assembler Directives.MODEL SMALL.DATA ORG 7000H POINTS DB 16 DUP(?) SUM DB ?.CODE ORG 8000H TOTAL: MOV AX,7000H MOV DS,AX MOV AL,0 RET END TOTAL  Simplified Segment Directives  Predefined.Mode Types DATA SEGMENT CODE SEGMENT TINYone SMALLone MEDIUMonemultiple COMPACTmultipleone LARGEmultiple HUGEmultiple FLAT*one * Flat is used for 32-bit addressing

8 7-8 Build Executable Programs Syntax check Translate source files into machine code Source files Assembler Linker OBJ files OBJ files library Executable files  Assemblers Question: What is the difference between *.com and *.exe files? http://www.faqs.org/faqs/msdos-programmer-faq/part2/section-9.html  Microsoft ML, LINK, & DEBUG  8086 Emulator  A86  MASM32 package 

9 7-9 Microsoft MASM and Debug  Microsoft MASM and Link Programs ML /c /Fl numoff.asm Link numoff  Microsoft Debug Program C:\> debug - a 0BDF:0100 MOV AX, 40 0BDF:0103 - t AX = 0040 BX = 0000 CX = 0000 DX = 0000 SP = ……………. ………………………………………….. - q Syntax check; Translate assembly instructions into machine codes Build the executable file

10 7-10 8086/8088 Assembler and Emulator

11 7-11 Difference Between EXE and Binary Files.model small.data org 0010H Var1 DB 12H.code MOV AX, 0000 MOV DS, AX label1: MOV AL, DS:[0100H] JMP label1 end.model small 0000.data org 0200H 0200 12Var1 DB 12H 0000.code 0000 B8 0000MOV AX, 0000 0003 8E D8MOV DS, AX 0005 A0 0100label1: MOV AL, DS:[0100H] 0008 EB FBJMP label1 end  Source File  List File

12 7-12 Difference Between EXE and Binary Files  EXE file  Binary file


Download ppt "7-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Introduction to Assembly."

Similar presentations


Ads by Google