汇编语言复习资料天津大学王建荣 联系客服

发布时间 : 星期日 文章汇编语言复习资料天津大学王建荣更新完毕开始阅读8a0ddc7f27284b73f2425022

digitStr BYTE \ ; 9

6.LABEL伪指令

?Assigns an alternate label name and type to an existing storage location

?LABEL does not allocate any storage of its own ?Removes the need for the PTR operator

用例: .data

dwList LABEL DWORD wordList LABEL WORD

intList BYTE 00h,10h,00h,20h .code

mov eax,dwList ; 20001000h mov cx,wordList ; 1000h mov dl,intList ; 00h

1. 间接寻址

0 间接操作数

(1)An indirect operand holds the address of a variable, usually an array or string. It can be dereferenced (just like a pointer).

(2)Use PTR to clarify the size attribute of a memory operand. 用例: .data

myCount WORD 0

.code

mov esi,OFFSET myCount

inc [esi] ; error: ambiguous inc WORD PTR [esi] ; ok

2.变址操作数:把常量和寄存器相加以得到一个有效地址

有两种格式:[label + reg] 用例: .data

13

label[reg]

arrayW WORD 1000h,2000h,3000h .code

mov esi,0

mov ax,[arrayW + esi] ; AX = 1000h

mov ax,arrayW[esi] ; alternate format add esi,2

add ax,[arrayW + esi] 3.指针:包含其他变量地址的变量 用例: .data

arrayW WORD 1000h,2000h,3000h ptrW DWORD arrayW .code

mov esi,ptrW

mov ax,[esi] ; AX = 1000h

练习题:书P96 第7题 ,第8题 作业题

5、JMP 和LOOP

1.JMP指令导致向代码段内的目的地址做无条件转移。目的标号的偏移地址被装入指令 指针中。

格式:JMP 目的地址

JMP指令是无条件的,因此循环会屋休止地持续下去,知道满足其他条件退 出为止。

创建一个循环 top: . .

jmp top ;无限循环

2.LOOP指令:重复执行一块语句,执行的次数是特定的。

ECX被自动用作计数器,在每次循环后减1 格式:LOOP 目的地址

执行LOOP指令两步:

14

首先ECX减1

接着,与0比较。如果ECX!=0,跳转到目的地址; 如果ECX=0, 不发生跳转。

注意:循环开始之前将ECX初始化为0,结果循环

4292967296次。 循环的目的地址与当前地址只能在相距-128~+127字节范围内。 3.循环的嵌套:

.data

count DWORD ? .code

mov ecx,100 ; set outer loop count L1:

mov count,ecx ; save outer loop count mov ecx,20 ; set inner loop count L2: . .

loop L2 ; repeat the inner loop mov ecx,count ; restore outer loop count loop L1 ; repeat the outer loop

例题:书P98 整数数组求和

书P99 复制字符串

第五章 过程

一.与数据库链接

链接库是一个文件,其中包含了已经编译成机器码的过程 命令: link hello.obj irvine32.lib

二.书中的链接库

CloseFile – Closes an open disk file

Clrscr - Clears console, locates cursor at upper left corner

CreateOutputFile - Creates new disk file for writing in output mode Crlf - Writes end of line sequence to standard output

15

Delay - Pauses program execution for n millisecond interval DumpMem - Writes block of memory to standard output in hex DumpRegs – Displays general-purpose registers and flags (hex) GetCommandtail - Copies command-line args into array of bytes GetMaxXY - Gets number of cols, rows in console window buffer GetMseconds - Returns milliseconds elapsed since midnight

GetTextColor - Returns active foreground and background text colors in the console window

Gotoxy - Locates cursor at row and column on the console

IsDigit - Sets Zero flag if AL contains ASCII code for decimal digit (0–9) MsgBox, MsgBoxAsk – Display popup message boxes OpenInputFile – Opens existing file for input

ParseDecimal32 – Converts unsigned integer string to binary ParseInteger32 - Converts signed integer string to binary

Random32 - Generates 32-bit pseudorandom integer in the range 0 to FFFFFFFFh

Randomize - Seeds the random number generator

RandomRange - Generates a pseudorandom integer within a specified range ReadChar - Reads a single character from standard input ReadFromFile – Reads input disk file into buffer

ReadDec - Reads 32-bit unsigned decimal integer from keyboard ReadHex - Reads 32-bit hexadecimal integer from keyboard ReadInt - Reads 32-bit signed decimal integer from keyboard ReadKey – Reads character from keyboard input buffer

ReadString - Reads string from standard input, terminated by [Enter]

SetTextColor - Sets foreground and background colors of all subsequent console text output

StrLength – Returns length of a string

WaitMsg - Displays message, waits for Enter key to be pressed WriteBin - Writes unsigned 32-bit integer in ASCII binary format.

WriteBinB – Writes binary integer in byte, word, or doubleword format WriteChar - Writes a single character to standard output

WriteDec - Writes unsigned 32-bit integer in decimal format WriteHex - Writes an unsigned 32-bit integer in hexadecimal format

WriteHexB – Writes byte, word, or doubleword in hexadecimal format WriteInt - Writes signed 32-bit integer in decimal format

WriteString - Writes null-terminated string to console window WriteToFile - Writes buffer to output file

16