The first week of Linux kernel design--from the assembly language to understand how the computer works Song Juning (20135315) I. The experimental process figure 1 writing songchenning5315.c fileFigure 2 Compiling a C file into a 32-bit machine languageFigure 3 Removing the link statement from the. s file to get the final assembly codeSecond, the analysis of stack
operate on the built-in TSC in the CPU. TSC is time Stamp Counter, a 64-bit timestamp counter provided for Pentium series CPUs, which is counted once per instruction cycle after the CPU is power up or reset, and Intel guarantees that the TSC overflow period is greater than 10. Like the 300MHz CPU we use, its TSC accuracy is about 33ns and the overflow period is about 19,303 years, which is perfectly in line with our project requirements.However, it is faint that the project cannot be compiled a
)+ ------ VM Virtual Mode flag (386 + only)
How about it? It seems that most of us are familiar with it before. Now, we only need to make fun of those on the 386The new register appears.
It must be emphasized that when programming in a 32-bit assembly language, all address offsets are 32-bit.Never use the original 16-Bit mode.
For general-purpose registers, 32-bit registers such as (Exx) are added, and its
Loading and running of the program (v)--"x86 assembly language: From the actual mode to the protection mode" Reading notes 25Some of the previous posts ended up parsing the code. This article is about compiling, running, and debugging the code.1. Compiling the code and writing the image fileWe both compile and write on the command line before we enter the command. When the source file is not considered trou
The previous compilation was not very good. By this microcomputer interface to the assembly language is to fill up.The following is a note of this time relative to the assembly language used in the microcomputer interface.PTRIn the case where there is no register name, the length of the memory unit is indicated by the
PIRATEZGW Original works reproduced please specify the source "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000 In fact, this is to deal with the work of the MOOC course, where the environment can not contact the Internet at any time, so submitted are relatively late, nonsense not much to say, into the topic. First, the operation of the experiment This is mainly in the Linux environment using VI + GCC to write C program code, and then compiled into
of the stacks. and ESP points to the top. We can use the offset of EBP to implement the access of local variables and parameters. The next thing we're going to talk about is how to return. In fact is the parameters in turn out of the stack, the last old Ebp pop up to now EBP. EBP refers to the bottom of the stack frame after the last. But we ask how the parameters are out of the stack, is it pop-up? What is the use of pop-up, because the local variables are useless after use, there is no need t
sa:0000(that is, an offset address of 0 for the starting address).
In the first 256 bytes of this memory area, a data area called the program segment prefix (PSP) is created, and DOS uses the PSP to communicate with the loaded program.
Starting at 256 bytes of this memory area (behind the PSP), the program is loaded and the program's address is set to sa+10h:0.
The segment address of the memory area is stored in DS , and after the other related registers are initialized, set the cs:
Direct addressingMOVL address,%eaxLoad the address into the%eax.Direct addressing, a bit like C, assigns a pointer variable to a value.Index addressingMovl String_start (,%edi, 1),%eaxThis instruction saves the value of address = (String_start address) + (the value inside the table%edi) * (the size of each element of the array) to the%eax.%edi is the subscript, 1 is the number of bytes per element of the arrayThe above index addressing a bit like C inside with subscript access character array, i
1, the procedure to obtain the required space of two ways, one is to load the program for the program allocation, and then the program in the process of implementation to the system application.2, we want a program to be loaded when the space required to obtain, you must be in the source program to make a description. We get the memory space by defining segments in the source program3. When the program runs, the CS register holds the segment address of the code snippet.4, used in the source prog
register the information of these stacks for temporary preservation in the TCB (e.g.).The steps for creating a stack of the X (x=0,1,2) privilege level are as follows:1. Apply for memory, allocate space for stack;2. Create a stack segment descriptor (DPL=X) in the LDT;3. Register the Stack's information in the TCB, including the stack size, base address, selector (rpl=x), and initial value of espx (=0);I think the size of the stack and the registration of the base site is not necessary, because
[Directive statement]Each instruction statement produces a command code (that is, the target code) that can be executed by the computer when the source assembly is compiled, so this statement is called an executable statement. Each instruction statement represents a basic ability of a computer, such as data transfer, two number addition or subtraction, shift, etc., which is done in the target program (the ordered collection of instruction code) is run
(required?? 8 words, insufficient blanks) RESB 18; Empty 18 bytes first; Program Body Entry:mov ax,0; Initialize the accumulator register MOVSs,ax; The stack register is initially 0 MOV sp,0x7c00; The stack pointer register is assigned a value of 0X7C00mov ds,ax; Data segment Register Clear 0 mov es,ax; add segment register clear 0 mov si,msg; add msg address into SI register Putloop:mov AL,[SI]; ADD si,1; Give Si plus 1 CMP al,0 JE fin MOV ah,0x0e; display a text MOV bx,15; specify character
From Chapter 8 of Intel assembly language programming (Fourth Edition.
Let's first take a look at the value transfer, the value transfer is relatively simple, look at the following code:
. Data
Mydata word 1000 h; this never changes
. Code
Main proc
Invoke sub1, mydata
Exit
Main endp
Sub1 proc somedata: Word
MoV somedata, 0
RET
Sub1 endp
The program uses the invoke command to pass the value of mydata
The content comes from Intel assembly language programming (Fourth Edition) Chapter 11th -------- 32-bit windows programming.
We should first write the content into the file (if there is no file, a new file will be created), and then read the content from the file.
First, let's take a look at writing data to a file:
Title using writefile (writefile. ASM)
Include irvine32.inc
. Data
Buffer Byte "this t
This piece of code comes from Intel assembly language programming (version 4)
;----------------------------------------------------------------------------
Arraysum proc
;
; Calculates the sum of an array of 32-bit integers.
; Es: ESI = the array offset
; ECx = number of elements in the array
; Returns: eax = sum of the array elements
;----------------------------------------------------------------------
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service