Jun 10 2010

1. “Hello world” ── 引导程序(Boot loader)

Category: OSDevwuxicn @ 9:23 AM
« Previous TOP » Next

======

1. “Hello world” ── 引导程序(Boot loader)

做好了准备工作,现在可以开始写操作系统了。一般学习编程的第一个程序都是“hello world”,因此我们的操作系统也不例外。下面看看用10分钟的时间如何写一个可以在裸机(虚拟机)上直接运行的“操作系统”。

我们的 “Hello world” 操作系统

Continue reading “1. “Hello world” ── 引导程序(Boot loader)”

Tags: ,


Apr 15 2010

What does CALL instruction do in assembly?

Category: Uncategorizedwuxicn @ 8:52 AM

CALL instruction do nothing except push IP into the stack (doesn’t like function call in C).
More specific, there’re 2 kinds of CALL:

1. Near call: if it’s a near call, the assembly does those two things:
1) push EIP into the stack,
2) set EIP to the address of beginning of your function.

2. Far call: if it’s a far call, the assembly does the following FOUR things:
1) push CS into the stack (save old code segment),
2) push EIP into the stack,
3) set CS to the new code segment which your function addressed,
4) set EIP to the beginning address of your function.

BTW, the RET instruction does the reverse operations.

Tags: ,


Apr 10 2010

Win32 内存中的栈与函数调用约定(

Category: Uncategorizedwuxicn @ 12:56 AM

注意:本文是针对Win32的,对linux下的gcc不适用!

1. 栈 Stack

在内存中,栈(Stack)是从高地址往低地址增长的[1](从上到下布局的),例如:

1052h |------| < -- sp
1051h |------|                /\
1050h |------| push ||    pop ||
104Fh |------|      \/
104Eh |------|

即当前sp在1052h位置,push了1 Byte以后,sp = sp - 1 即:1051h。

并且,数据存放时按照我们正常的逻辑存放,高地址存放数据的高字节、低地址存放数据的低字节,例如:
当前sp=1052h, push word 0x1234 时,先将高字节0x12存入sp-1的位置(1051h),再将0x34存入sp-2位置(1050h),然后sp = sp - 2 (sp变为1050h) [1].

2. 函数调用约定 Calling Convention

Continue reading "Win32 内存中的栈与函数调用约定("

Tags: , , , ,


Apr 02 2010

x86寄存器

Category: Uncategorizedwuxicn @ 4:38 PM

INTEL 80×86 CPU有下面这些寄存器:

通用寄存器 (General Purpose Registers)
1. EAX (AX/AL/AH) Accumulator.
2. EBX (BX/BL/BH) Base
3. ECX (CX/CL/CH) Counter
4. EDX (DX/DL/DH) Data

注: Exx 是32位寄存器,在80386+的CPU才有。
Continue reading “x86寄存器”

Tags: ,


Nov 15 2009

gcc -S 将c源程序编译成汇编代码

Category: Uncategorizedwuxicn @ 10:00 PM

用gcc将C的源程序进行部分编译,将其翻译成汇编代码(不进行目标代码的编译和链接)。
方法:gcc -S
例子:
gcc -S hello.c

通过这个可以看看写的代码将会生成的汇编,分析代码的效率。

Tags: ,