当前位置:网站首页>Chapter IV - first procedure

Chapter IV - first procedure

2022-06-12 08:52:00 Pickup Ping

4.1 The process of a source program from writing to execution

Write assembly source program

Using the text editor , Use assembly language to write assembly source program .

Compile and connect

  • Compile programs in assembly language (MASM.EXE) Compile the source program in the source program file , Generate target file ;
  • Reuse connection program (LINK.EXE) Connect to the target file , Generate executable files that can be run directly in the operating system .

Executable file

  • Program ( Machine code translated from assembly instructions ) And data ( Defined data )
  • Related description information ( such as : How much memory does it take , How big the program is )

Execute the program in the executable file

  • Execute the program in the executable file in the operating system .
  • The operating system follows the description in the executable file , Load the machine code and data in the executable file into memory , And initialize , Then from CPU Execution procedure .

4.2 Source program

  • Assembly instruction
    from CPU distinguish , Corresponding machine code
     Insert picture description here

  • Pseudo instruction
    Understood by the compiler ,CPU Cannot read . Tell the compiler how to execute our code .
     Insert picture description here
    XXX segment( paragraph )
    XXX ends

  • segment and ends Is a pair of pseudo instructions , The function is to define a segment , The former represents the beginning , The following represents the end .

  • end Is the end of an assembler .

  • assume: If 、 hypothesis .

label

  • A label represents an address
  • codesg: Put it in segment In front of , As the name of a segment , The name of this segment is finally

DOS Program running in

  • DOS Is a single task operating system .
  • At the end of a program , take CPU The controller is returned , This is called : Return of program
  • To add the returned program segment at the end of the program .
  • The function of these two instructions is program return .
mov ax,4c00H
int 21H
## interrupt 

End of paragraph 、 Program end 、 Program return

 Insert picture description here

Grammatical and logical errors

  • Grammar mistakes , Errors found by the compiler at compile time ;
  • Logic error is something that a program cannot show at compile time 、 What happens at runtime .

About compiling and linking

  • compile : Assembly language is translated into machine language
  • Connect : Connect the target files together , Generate an executable file .

4.8 The principle that programs in executable files are loaded into memory and run

  • stay DOS in , Programs in executable files P1 To run , There must be a running program P2, take P1 Load into memory from an executable , take CPU Give it control of ,P1 To run ; When P1 Operation completed , Should be CPU Control of the is returned to CPU So that it can continue to run the program P2
  • We are DOS Run directly in 1.exe when , It's running command take 1.exe The program in is loaded into memory .
  • command Set up CPU Of CS:IP The first instruction to the program ( It's the entry point of the program ), So that the program can run .
  • At the end of the program , Back to command in ,CPU Continue operation command.

 Insert picture description here

The shell of the operating system

  • DOS There's a program in command.com, This program is in DOS Called command interpreter in , That is to say DOS Systematic shell

4.9 Tracking of program execution process

 Insert picture description here

summary :EXE The loading process of the program in the file

  • After the program is loaded ,ds The segment address of the memory area where the program is stored in , The offset address of this memory area is 0, The address of the memory area where the program is located is :ds:0;
  • The front of this memory area 256 In bytes are PSP,dos Used to communicate with programs .
  • from 256 The space behind the byte is for the program .
  • so, We from ds You can get PSP Section address of SA,PSP The offset address of is 0, Then the physical address is :SA×16+0.
  • because PSP Occupy 256(100H) byte , So the physical address of the program is :
    SA×16+0+256=(SA+16)×16
    The segment address and offset address can be expressed as :SA+10:0

command :

  • use U Command view other instructions ;
  • use T Command but not execute every instruction in the program , And observe the execution result of each instruction
  • here we are int21, We need to use it. P Command execution
  • Come back to debug,q go back to command
原网站

版权声明
本文为[Pickup Ping]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120842166024.html