Microcomputer principle including assembly language courseware, microcomputer principle and interface technology - seven chapters - assembly language and assembly program courseware.ppt...

"Microcomputer Principles and Interface Technology-Chapter Seven-Assembly Language and Assembly Program Courseware.ppt" is shared by members and provides online free full-text reading and download. This document format is ppt, and more related "Microcomputer Principles and Interface Technology-Chapter Seven- "Assembly Language and Assembly Program Courseware.ppt" document, please search in Tiantian Library.

1. 7.1 Basic syntax of macro assembly language 7.2 Pseudo instruction 7.3 Macro instruction 7.4 System function call 7.5 Assembler function and assembly process Chapter 7 Microcomputer assembly language and assembler 7.1 Basic syntax of macro assembly language Assembler: used to The program written in assembly language is automatically translated into the software label name pseudo-instruction operand of the destination program; note, 7.1.1 There is no colon in the pseudo-instruction statement format! Constant name, variable name, procedure name, structure name, record name, etc., constant string, constant name, variable name, label, special symbol (such as BYTE, FAR...) Memory data definition directive 7.1.2 Constants, variables and labels Constants: pure numerical values ​​without any attributes. It does not change while the program is running. Such as: 10010011B, 0A5H, "ZHIFUCHUAN" variable: represents the storage unit, the number in the unit can be modified at any time during the program running. Variable name: the symbolic address of the data unit. Label: indicates the storage unit, and the machine instruction code is stored in the unit. ① Segment attribute (SEG): The variable or label corresponds to the segment value of the segment where the storage unit is located. ② Offset attribute (OFFSET): The variable or label corresponds to the segment of the starting address of the storage unit.

2. Internal offset ③Type attribute (TYPE): The variable type is mainly byte (BYTE), word (WORD), double word (DWORD) The label type is mainly near (NEAR) and far (FAR) - there are three attributes: -- Segment address: the segment address of the segment where the label is located; -- Offset: the offset address within the segment of the storage unit represented by the label; -- Type: NEAR or FAR: NEAR—represents the statement and branch instruction/call where the label is located The instructions are in the same code segment, and only need to change the IP when jumping. FAR—The statement where the label is located is not in the same code segment as the branch/call instruction. If the type is not specified, the default is NEAR. - The label is usually used as the branch address of the branch instruction or CALL instruction. Label - the symbolic address variable of the memory unit where the instruction is located - that is, the storage unit or data area in the memory. Variable name - is the symbolic address or name of the storage unit (data area). - Variables also have three attributes:-- Segment address - the segment address of the segment where the variable is located - Offset - the displacement between the variable unit address and the first address of the segment. -- Type—There are three types: BYTE, WORD, and DWORD. - Variables.

3. Referenced in the program as a memory operand. The rules for using variable labels and variable names consist of: AZ (case-insensitive), 0-9, ? @ . _ $ can not start with a number, period (.) can only be used as the first character length less than 31 characters can not be the same as reserved words (instruction mnemonics, directives, predefined symbols, etc.) can not be repeated definition for example: correct : LP1, AGAIN, NEXT, _GO, OK_1 False: 4M, LOOP, AAA, #HELP, +ONE (P457) An example in assembly language: hello.asm data SEGMENTHello DB 'Hello, world!',0DH,0AH, '$'data ENDSprog SEGMENT ASSUME CS:prog,DS:datastart: MOV AX,data MOV DS,AX LEA DX,hello ;take the first address of the string MOV AH,9 INT 21H ;display the string MOV AH,4CH INT 21H ; .

4. Return to DOSprog ENDS END start name label ORG 100HX DB 33HY DW 0A65DH variable name MOV AL, XMOV BX, Y7.1.3 Expressions and operators (1) Expressions: formulas composed of operands and operators (1) Arithmetic operations Symbols: +, -, *, /, MOD (remainder after division), SHL (shift left), SHR (shift right) Example: MOV AX, 100*4+5; AX=405 (2) Logical operators: AND, OR, NOT, XOR Example: 24H OR 0FH=2FH bitwise operation (3) Relational operation: EQ, NE, LT, LE, GT, GE Example: MOV AX, 1234H GT 1024H The relational operation result is always a numerical value. If the relationship is not established, the result is 0, if the relationship is established, the result is 0FFFFHMOV AX, 0FFFFH- for numeric expressions: MOV AX , 4*1024 The assembled form is: MOV AX , 4096 - for address expressions, Example: LEA SI , TAB+3 if TAB.

5. If the offset address is 1000H, the assembled form is: LEA SI , [1003H] Example 1) Arithmetic operators - +, -, *, /, MOD logical operators can only be used in digital expressions . Example: MOV CL , 36H AND 0FH After assembly: MOV CL , 06H Be careful not to confuse logical operators with logical operation instructions: Example: AND AX , 3FC0H AND 0FF00H After assembly, the source operand is translated as: 3F00H, so the above The instruction is equivalent to AND AX, 3F00H. Example 2) Logical operators - AND, OR, XOR, NOT- The result of the relational operation is a logical value: true or false, the relation is true, the result is all 1, the relation is false, and the result is all 0 Example: MOV BX, PORT GT 300H If the value of PORT is greater than 300H, the assembly will be: MOV BX, 0FFFFH, otherwise the assembly will be: MOV BX, 0 Example 3) Relational operators - EQ, NE, LT, GT, LE, GE⑷ Analytical operators ( Numeric echo operator): SEG(count.

6、算段基址) OFFSET(计算偏移地址) TYPE(计算符号类型值) SIZE(计算符号名分配的字节数)(=TYPE*LENGTH) LENGTH(计算符号名分配的数)7.1.3 表达式与运算符(2)例2:把VARW的偏移地址送BX MOV BX,OFFSET VARW例3:假设VARW变量是字变量,把VARW的类型值送AL MOV AL, TYPE VARW ;AL =2例1:把VARW所在段的段值送AX MOV AX,SEG VARW变量名SEG:取变量/标号的段地址OFFSET:取变量/标号的偏移地址例:VAR DB 12H …… MOV BX,OFFSET VAR ;取变量VAR的偏移地址 MOV AX,SEG VAR ;取变量VAR的段地址注意,以下指令的异同: MOV BX, OFFSET VAR LEA BX, VAR- OFFSET只能取静态的偏移地址;- LEA指令即可取。

7、静态的偏移地址,也可取动态的偏移地址。 例4)取地址运算符——SEG、OFFSETTYPE 。省略部分。ta MOV DS, AX MOV ES, AX MOV AX , stack MOV SS , AX MOV AL, 4CH INT 21H code ENDS END start 堆栈段数据段代码段汇编程序编程应注意的问题任何一个源程序必须至少有一个代码段,其它段视程序要求而定。段寄存器的装填(DS、ES、SS由用户自行装填,CS不须用户处理)。 方法: MOV AX,**** MOV DS,AX (或ES、SS)DOS下汇编程序的正常结束 方法1: MOV AH,4CH INT 21H 方法2: 程序名: PROC FAR PUSH DS MOV AX,0 PUSH AX ……. RET 程序名 ENDP7.5.1 汇编程序的功能(EDIT)汇编语言源文件(.ASM)汇编程序(MA。

8、SM或ASM)目标代码文件.BOJ列表文件.LST交叉索引文件.CRF输入翻译输出汇编程序的功能就是把用助记符书写的汇编语言源程序,翻译成机器语言目标代码;同时进行语法检查,指出语法错误所在行的行号。在计算机上运行汇编语言程序的步骤用编辑程序建立XX.ASM程序用汇编程序把XX.ASM程序转换成XX.OBJ程序用连接程序把XX.OBJ程序转换成XX.EXE程序用调试程序调试程序 XX.EXE用DOS命令直接键入程序名执行文本编辑EIDT汇编程序MASM连接程序LINKDEBUG编辑源文件(用EDIT)文件存盘用MASM汇编源文件(.ASM)生成目标代码文件(.OBJ)开始有语法错?用LINK连接目标代码文件生成可执行文件(.EXE)有语法错?在DOS下执行.EXE文件程序运行有错?调试文件(DEBUG)结束YYY7.5.2程序的编辑、汇编及连接扩展名为.ASM的文件1. 编辑程序EDIT 。

9、文件名.ASM 回车在DOS方式下输入程序存盘2. 汇编程序MASM 文件名;回车缺省方式,以源文件名为目标文件名,无列表文件;无交叉索引文件如果有语法错误,用EDIT修改文件3. 程序连接LINK 文件名;回车上机步骤:5. 调试程序DEBUG 文件名. EXE 回车进入了DEBUG调试状态4. 执行程序文件名 回车如果执行程序有错,进入第5步DATA SEGMENT … ;存放数据项的数据段DATA ENDSEXTRA SEGMENT … ;存放数据项的附加段EXTRA ENDSSTAC SEGMENT PARA STACK … ;作堆栈用的堆栈段STAC ENDSCOSEG SEGMENT ASSUME CS:COSEG,DS:DATA ASSUME SS:STAC,ES:EXTRABEING:MOV AX,DATA MOV DS,AX … ;存放指令序列COSEG ENDS END。

10、 BEING7. 6汇编语言程序设计构造一个源程序的基本格式:DEBUG程序命令(1)A命令(汇编命令) 格式:A [ 地址] 功能:从指定地址把宏汇编语言语句直接汇编入内存2. D命令(显示命令) 格式:D [ 地址] 或 D [ 范围] 功能:从指定地址开始显示内存中80H字节的内容, 或显示指定范围的内容地址:由段值和偏移两部分组成。如 DS:100,段值可以省略 范围:有两种表示方法,一种是用起始地址和结束地址如DS:100 110, 另一种用起始地址和长度表示。如DS:100 L10 说明:DEBUG程序命令(2)G命令(执行命令) 格式:G [=起始地址][断点地址表] 功能:从当前地址或指定地址执行遇到断点停止执行R命令(寄存器命令) 格式:R ;显示所有寄存器的内容 R 寄存器名 ;显示并可修改寄存器的内容 RF ;显示并可修改标志寄存器的内容Q命令(停止命令) 格式:Q 功能:退出DEBUG程序,不保存内存中调试的文件DEBUG程序命令(3)T命令(跟踪命令) 格式:T [=地址][数值] 功能:从当前地址或指定地址执行一条或指定的条数指令 并显示各寄存器的内容及下一条要执行的指令U命令(反汇编命令) 格式:U [范围] 或 U [地址] 功能:把指定范围的内容反汇编或从指定地址开始反汇 编16条DEBUG程序命令(4) 格式:E [地址] [表] 功能:用表中的内容替换内存中一个或多个字节里的内容 (表中的数据以空格分隔,一个数据代表一个单元 的内容)8. E命令(修改内存单元命令)例:把当前数据段,100H开始的连续单元分别修改为 11H,22H,33H,44H,55HE 100 11 22 33 44 55。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324085620&siteId=291194637
Recommended