Wednesday, October 13, 2010

Assembly language instruction and by Example


From how to build the source file to debug a brief introduction to the next, and explain with examples. Since I is limited, if any errors below and in the place where you can further modify said please
Assembly language course:
First, prepare the machine before the software:
MS-DOS operating system (such as: MSDOS6.22, MSDOS7.0, etc.)
Text editor (such as: ED99v.COM, TURBO.EXE, TC.EXE, C. EXE, etc.)
Assembler (such as: MASM.EXE, ASM.EXE, etc.)
Connect program (such as: LINK.EXE, etc.)
Debugger (such as: DEBUG.EXE, etc.)

Second, the compilation process of establishing procedures for:




a. Through the establishment of assembly source code 鈹?鈹?鈹?鈹?鈫?b. compiled to object files 鈹?鈫?鈹?鈹?鈫?d. Connect to the executable file
鈫?br />鈹?c. do not pass, re-edit (statement error) 鈫?br />鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈫?br />鈫?f. is not correct, use the debugging tools to debug, re-modify the (logical errors) 鈫?br />鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈹?鈫?e run
鈫?correct
g. complete


3, now (b) marked with the letters of each process (PROCEDURE) for details

PROCEDURE a: the establishment of assembly source code (ie: the establishment of the file name. Asm)
This process is equivalent to the paper we write source code, only the paper into a computer, this process also known as source code entry. Source code will be many ways to input the computer, the following specific methods will be introduced.
1. Through MD-DOS text editor that comes with ED99v.EXE for input, in the DOS prompt, type: ED99v carriage return, then the system if you can call, ED99v operation screen will appear on the screen, You can be the prompt for input, and when the entry is completed, select Save and give you a file from the input file name, format: filename.asm; (where filename for you from the file name, by the characters 1-8 composition), asm is the assembler must be added to the identification, can not be changed. Save the file after the DOS command DIR is available under DOS to see if you find documents stored there, you can process b.
2. If your system does not ED99v, can also be you are familiar with a text editor to input, edit, such as the available c language and pascal language text editor to edit, and finally the form of documents can be saved as filename.asm .

PROCEDURE b: compiled object files (ie: compile. Obj. Lst. Crf file)
This process is the computer will correct your source code compiled into machine language, program listings and cross-reference table of the target file. If the statement at this time your application has an error, the system error, and pointed out that in the first few lines, what types of errors, you can suggest changes to each. Specific process are presented:
In the DOS prompt, type MASM filename ENTER
(Note: Your assembly program within the system as MASM.EXE, if your system is ASM.EXE assembler, and put order into the ASM filename Enter. Which filename you just created in the PROCEDURE a file name)
Then the assembler output file can have three (respectively:. Obj. Lst. Crf), there will be three questions, the way in which you can press Enter. The information shown below is the source of the error number, said if passed is 0, the process can be c. But if not for the 0 to illustrate the error, and that the line the error occurred, can be modified according to the prompt. However, if the error has not so much see the show passed the following order form will be available error message stored in a file you specify, and then a text editor to view. MASM filename> filen (filen since you have not used a file name to store error information) later to see filen to get an error message.

PROCEDURE c: compile do not pass, re-edit (error type: source statement is illegal)
After the implementation of over PROCEDURE b, if an error message, we should do our own press PROCEDURE c, and not jump to the PROCEDURE d, and if the Executive PROCEDURE d force will be no effective results.
Now open is misplaced it! First of all, make it clear, in the PROCEDURE b errors are detected in the syntax of each statement or the use of an error, it can not detect the logical design process (statement by row position) errors, so we'll remember good error line number. After the line number in the record, it should be re-implementation of the PROCEDURE a, time and action should be open source code has been programmed (to ED99v example: In the DOS prompt, type:
ED99v filename.asm carriage return), according to the line number to edit and save the file, compile again, until PROCEDURE b by far. Will continue down the implementation of the PROCEDURE d.
Here are some common error messages, in order to check:

1, Register already defined to internal logic error in compilation
2, Unknown symbol type in the symbol type of statement, some things can not be identified
3, Symbol is multi-defined repeat the definition of a symbol
4, Symbol not defined symbol is not defined
5, Syntax error statement syntax and grammar of any recognizable does not match
6, Symbol is reserved word
Attempted illegal use of an assembler of reserved words (example: add the definition of a variable)
7, Not proper align / combine type SEGMENT parameter is incorrect
8, One operand must be const it is illegal to use addition instructions
9, Operands must be same or 1 abs this is the illegal use of subtraction instruction
10, Already have base register base address of trying to duplicate
11, Illegal size for item reference to the length of the items is illegal, (such as: double word shift)
12, Illegal register value into the specified value can not register "reg" field
13, Must be AX or AL or some commands can only AL AX
14, Improper use of segment reg segment register to use illegal (such as: mov ds, 0)
15, Division by 0 or overflow gives an expression to use 0 for division
16, value is out of range values greater than the need to use
17, CS register illeal usage tried to register the illegal use of CS
18, DUP is too large for linker
DUP nested too long, so that the linker can not get from the record to be

PROCEDURE d: Connect to the executable file (ie: to connect to. Exe or. Com file)
In this process, generally do not have accidents, that is, if the file name wrong.
Type: In the DOS prompt: LINK filename ENTER

PROCEDURE e: run the compiled executable file
When PROCEDURE d passed, will produce an executable file, then simply run the program to see if it did according to what you imagine the outcome. During the pilot, to try to test some of the critical state, to see whether the procedures and stable operation, the result is correct. If everything works, can enter PROCEDURE g the.
May fear most is not OK, procedures produce some strange results (you can not think that is your computer does not listen to your command, in fact it is meticulously compiled in accordance with your procedures. I have always thought that my computer out the problems), if on the test time must not panic, hold their emotions, do not read the computer, quiet a few minutes (time is loads anyway). Then we should use the most critical and most common step in the conduct PROCEDURE f.

PROCEDURE f: using debugging tools to debug, re-modify the (logical errors)
In this I will introduce in the own use DOS debugger DEBUG.EXE to program debugging, check for errors.
First of all we have to understand basic use of DEBUG:
1, for debugging program input format:
DEBUG FILENAME.??? Enter
Where FILENAME is the main file name??? Is the extension file name, such as we had already compiled a file, it's name to: djx.exe to debug it at the DOS prompt when
Play: DEBUG djx.exe Enter, to see the''-'' prompt, without any prompts are correct, can debug it.
2, DEBUG DEBUG debug commands used in the process of introduction:
(Note: In the command using [] enclosed content can be the default)
1) D (Dump) show the contents of the specified memory modules (see the data with a number of general content, namely, DS section):
Format: d [address] from [address] the designated memory cell shows the contents of 128 bytes
[Address] by default, display the contents of the back of a DUMP command
d address range display the contents of the specified range of memory.
Example:-d100 show from the beginning of the content of DS Section 100H (hexadecimal display)

2) E (Enter) modify the contents of memory cells (typically in the DS section)
Format: e address [data] with a given [the data] to replace the contents of the specified range of storage units
e address of the memory cell changes the contents of a specified
Example:-e ds: 200''djx''FF00AA DS segment can be started from 200 to 205 of content for
For the 64 6A 78 FF 00 AA

3) G (GO) to run the command
Format:-g [= address] [break address 1 [breakpoint address 2 ... [breakpoint address 10]]]
From the specified [address] to start the implementation process (such as the address of the default from the current CS: IP starting), run to the [Breakpoint Address 1] to stop, show the contents of all registers and flags with the next instruction, such as after that there are breakpoints, can type g, continue.
Example:-g001a the execution from the current cs: ip to 001a of Directive
Note: Address setting must be set from the command from the first byte.

4) T (Trace) to execute a statement
Format:-t [= address] from the specified [address], after a statement from the implementation of the stop to show the contents of all registers and flags of the value of the next instruction. Such as [address] the default from the current CS: IP starting execution
-T [= address] [value] since the implementation of value from the specified address after the instruction to stop.

5) P (proceed) to perform a loop; a soft interrupt or subroutine call
Format:-p [= address] [n]
Example: mov ah, 02h
mov dl, 41h
int 21h
This time with:-p Enter the system will display a character A, if not in the P, while the switch T, then the system will enter the INT 21H interrupt call, get out, then you will think you program code is wrong, some attention!!

6) R (register) display and can modify the register contents
Format:-r Display the contents of all registers
-R register name changes the contents of the specified register (can be changed: AX, BX, CX, DX, SP,
BP, SI, DI, CS, DS, ES, SS, PC, IP, F)

7) U (Unassemble) disassemble
Format:-u [address] from a specified [address] Disassembly of 32 bytes, if the [address] from the current address of the default compilation of 32 bytes.
-U address range within the specified storage unit disassembly

These are the debugger commands may be used to explain DEBUG, DEBUG there are other commands will not be used in the inspection process, it is no longer introduced.

PROCEDURE g: program compiled well, it all OK!!! An assignment away with it! Eat, sleep.

The following procedure gives a wrong sentences, I hope you join me in debug, modify and adopt:
PROCEDURE a first implementation of the source code editor
Implementation function: on the screen: Hello world
My name is DJX
File Name: error.asm
Line number: source code:

1 data segment
2 out1 db''Hello world''
3 ax db''My name is DJX''
4 data ens
5
6 code segment
7 assume cs: code; ds: data
8 lea dx, out1
9 mov ah, 2
10 int 21h
11
12 mov dl, 0ah
13 mov ah, 2
14 int 21h
15 mov dl, 0dh
16 moo ah, 2
17 int 21h
18
19 lea dx, ax
20 mov ah,
21 int 21h
22 code ends

After you edit the implementation of the PROCEDURE b compile with masm: masm error Enter revealed the following:
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.

Object filename [error.OBJ]:
Source listing [NUL.LST]:
Cross-reference [NUL.CRF]:
End of file encountered on input file
error.ASM (23): warning A4085: End of file, no END directive
Open segments: DATA
error.ASM (3): warning A4016: Reserved word used as symbol: AX
error.ASM (4): error A2105: Expected: instruction or directive
error.ASM (16): error A2105: Expected: instruction or directive
error.ASM (19): error A2049: Illegal use of register
End of file encountered on input file
error.ASM (23): warning A4085: End of file, no END directive

51566 + 406450 Bytes symbol space free

2 Warning Errors
4 Severe Errors

Illustrate this process wrong, and wrong in the first 3,4,16,19,23 line,
Let us go one by one, checking the implementation of PROCEDURE c
Third row: 3 ax db''My name is DJX''
Its error is not as variable names AX, corrections:
3 out2 db''My name is DJX''
Note that we have just AX for the variables defined in the following process variables AX''used''in the 19th row
19 lea dx, ax
Also reported in the error report, the first 19 lines wrong, because the effective address can not be assigned AX DX, corrections:
19 lea dx, out2
This solved two mistakes about
Fourth row: 4 data ens
The end of a section of this act, but the statement is missing playing letters, corrections:
4 data ends
16th row: 16 moo ah, 2
This line is also the statement wrong, correct:
16 mov ah, 2
Twenty-three lines:
Error message: error.ASM (23): warning A4085: End of file, no END directive
The end of the present procedures do not counterfeit operations, corrections:
Adding: In the seventh, eight lines to address flag: start:
The original 23 end start

PROCEDURE a source code implementation will be amended as follows:

data segment
out1 db''Hello world''
out2 db''My name is DJX''
data ends

code segment
assume cs: code; ds: data
start:
lea dx, out1
mov ah, 2
int 21h

mov dl, 0ah
mov ah, 2
int 21h
mov dl, 0dh
mov ah, 2
int 21h

lea dx, out2
mov ah, 9
int 21h
code ends
end start

PROCEDURE b compile again, the screen shows:

Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.

Object filename [error.OBJ]:
Source listing [NUL.LST]:
Cross-reference [NUL.CRF]:
51524 + 406492 Bytes symbol space free

0 Warning Errors
0 Severe Errors

This procedure is no longer an error on the statement.
Executive PROCEDURE d connected again for the executable file (link error return), the screen displays:

Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.

Run File [ERROR.EXE]:
List File [NUL.MAP]:
Libraries [. LIB]:
LINK: warning L4021: no stack segment

Then error.exe executable file already exists, you can perform PROCEDURE e to run to see if the correct
In the dos prompt, type: error carriage return (be careful!!!)
Screen: garbled, and crash. reset My computer!
Help program logic error, and serious.
This is necessary to use the PROCEDURE f, with the debugging tools to debug and find the error.
In the DOS prompt, type: debug error.exe Enter
Screen appears - prompt, then you can use the DEBUG command came to mistake,
First, I use the d command to view the data area and content, the development of the two strings are not defined in the data section of the first paragraph, and in the data segment location within the 100h, when he come to have an unwritten rule masm, End of data that is in the definition section, the variables are defined 100h units back, we need to ds segment register set, the program's start: add the following directives: (Executive PROCEDURE a)
mov ax, data
mov ds, ax
Further implementation of the PROCEDURE b, PROCEDURE d, PROCEDURE e to run the program,
Screen Display:
Wrap
My name is DJX and garbled, and crash. (Have to reboot!)
PROCEDURE a re-implementation of the inspection process, that:
1. Assembly language are provided by the $ at the end of each string
2. The first string in the output statement in the AH sub-functions should be No. 09H
The above two corrections.
Further implementation of the PROCEDURE b, PROCEDURE d, PROCEDURE e to run the program,
Screen Display:
Hello world
My name is DJX and crash and can not return to DOS
Analysis, in the program did not return DOS commands, corrections:
PROCEDURE a used to edit:
Using DOS 21H interrupt 4cH submenu to return to the DOS, add the code ends before:
mov ah, 4ch
int 21h
Further implementation of the PROCEDURE b, PROCEDURE d, PROCEDURE e to run the program,
Screen Display:
Hello word
My name is DJX
And return to DOS
Success!
Completion of the commissioning of such a program, and correctly.
The following is the correct source:

data segment
out1 db''Hello world $''
out2 db''My name is DJX $''
data ends

code segment
assume cs: code; ds: data
start:
mov ax, data
mov ds, ax

lea dx, out1
mov ah, 9
int 21h

mov dl, 0ah
mov ah, 2
int 21h
mov dl, 0dh
mov ah, 2
int 21h

lea dx, out2
mov ah, 9
int 21h

mov ah, 4ch
int 21h
code ends
end start

The above procedure is simple, just to illustrate the realization of assembly language programming and debugging process on the machine, assembly language to be more practice to master its characteristics, in order to successfully pass the exam.






相关链接:



Evaluate Chat And Instant Messaging



Shenzhen Julong Year Launched China's First Six-generation LCD Line



"Sacred 2 Fallen Angel," Raiders Special mounts detailed process



Excellent Fujitsu UD board really gives whiteboard courseware courseware second life



MII further notice irregularities SP will be ordered to Stop



MKV to PSP



DOS, also use Flash tips



RM to AVI



SATA Disk Drives Imperfection



Best Search Or Lookup Tools



AVI TO FLV



3DS Max 7 Mental Ray Renderer Whole Strategy: Global Illumination



Lists Tools And Editors



How out of the trap of pseudo-BI



My favorite Animation Tools



mdcrashreporttool exe has stopped Working



No comments:

Post a Comment