Computer Basic

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 93

CPU

CPU
CPU
CPU

CPU

RLE
RLE
DLL
_stdcall

Windows CPU
API
FreeBSD Port

Java
BIOS

Windows
32
API
GUI
WYSIWYG

IN OUT

DMA
CPU
- CPU

CPU

CPU Central Processing Unit


CPU CPU

CPU
CPU

CPU

CPU
CPU RAM CPU

RAM : Random Access Memory RAM


CPU
CPU

CPU CPU
C

CPU

CPU ALU

ALU

CPU
/ I/O CPU CPU

CPU
CPU

CPU 20 - 100

CPU

CPU CPU
CPU
CPU
CPU

CPU 1 byte = 8 bits


CPU

CPU
CPU

hhhh

C
C++ Java
1 mov eax, dword ptr [ebp-8] /* eax */
2 add eax, dword ptr [ebp-0Ch] /* eax */
3 mov dword ptr [ebp-4], eax /* eax */

assembly (memonic)
mov,add
move addition

eax,ebp CPU CPU

CPU

CPU
CPU

(Program Counter)

PC
PC 1
123 456

0100 Windows
0100 1
CPU

+1

CPU 0100 0100 0101


PC +1 0102 0106 0 jump 0104
0103 if()
PC +1
jump

overflow

parity check

CPU

CPU XXX YYY


CPU
XXX YYY XXX YYY
XXX YYY CPU
a b 123 456 MyFun(a,b)
C 1 C
MyFun(a,b) MyFun(a,b) CPU

call return
call
return return MyFun
0154 MyFun 0154
call
return

00000000 - FFFFFFFF
32
: a[0] - a[4] [] 0-4

CPU

CPU

· CPU 5

CPU

Write Back WB
“ ” CPU
Memory CPU

CPU CPU
CPU

512M

IC

RAM

ROM ROM

Cache Cache L1 Cache


L2 Cache L3 Cache CPU
CPU CPU
Cache CPU

IC IC
IC
IC

VCC GND A0 - A9 D0 - D7 RD WR
VCC GND
0 1 +5V 1 0V 0

IC D0 - D7
8 bit = 1 byte A0 - A9
00000 00000 - 11111 11111 2 10 = 1024 1 byte
IC 1 KB

512 MB 512000 512 * 1000 IC


IC IC

IC IC
IC

IC 1byte

VCC +5V GND 0V A0 - A9


D0 - D7 WR write 1
IC
A0 - A9 RD 1

RD WR WR RD 0

1
1KB

1 //
2 char a;
3 short b;
4 long c;
5
6 //
7 a = 123;
8 b = 123;
9 c = 123;

a,b,c 123

1 char 2 short 4 long


123
123 short long
0

1 char *d; // char d


2 short *e; // short e
3 long *f; // long f
32 32 4 32
def

def 100 char


1 byte short 2 long
4

32 64

char 1 1

short int 2 2

int 4 4

unsigned int 4 4

float 4 4

double 8 8

long 4 8

long long 8 8

unsigned long 4 8
char short long
[value]

1 char g[100];
2 short h[100];
3 long i[100];

char short long 1 2 4

1 1

stack LIFO Last In First Out

push
pop
1 //
2 Push(123);
3 Push(456);
4 Push(789);
5
6 //
7 j = Pop();
8 k = Pop();
9 l = Pop();

LIFO Last In First On


(First In First Out)
:

1 //
2 EnQueue(123);
3 EnQueue(456);
4 EnQueue(789);
5
6 //
7 m = DeQueue();
8 n = DeQueue();
9 o = DeQueue();

EnQueue() DeQueue()
FIFO
(ring buffer)
6

p[2]
p[2] p[2] p[1]
p[2]

p[2] p[3] p[6]


p[6] p[2] p[6] p[6] p[3]

50
50 50
IC CPU IC
CPU

CPU
CPU IC IC
CPU IC (Integrated
Circuit)

IC

IC IC : 0V 5V IC
0 1 0 1
0 1 10 11 100 101
IC

(bit) 8 16 32 64
8 8 8
8 8 bit

1 8 8

(= ) 0

100111 6 0 00100111 16
0000 0000 0010 0111

32 64 32 4 64
8
00100111
*

00100111 39 39 3 9
3 * 10 + 9 * 1 10 , 1
7 6 5 4 3 2 1 0 2 7 2 6
2 2 10
-1 1-1=0 2-1=1

0 1 2
* 3 * 10 + 9 *
1 = 39

2
39 39 0010 0111 <<
0100 1110 78
78 39 2 0010 0111 1001 1100
156

>>
1/2 1/4 39

0 1
0 1

0 1 -1
1 0000 0001 -1 1000
0001

100 - 50 100 + (-50)

+1
-1

(0 ---> 1 , 1 --->
0) +1

1-1
1000 0001 ( 1
)

1-1

1-1 130 0 1000 0001 -1

1111 1111
1-1

1-1 1 + (-1) -1 +1 1111 1111 ,


1 1 0000 0000
1 0000 0000 0 1111 1111
-1

+1

0
3-5
3-5

3-5 1111 1110


+1 2 1111
1110 1 -2

C unsigned
short short 2
short -32768 - 32767 unsigned short 0-
65536

-32768 32767 0 0~
32767 32768 0 1 -1 ~ -32768 32768 0 0
0
1 0

(0 1)
1
1/2,1/4,1/8 0

-4

-4 63 1/4
-1 1/4
0

8 16 32
0111 1111 8 16 0000 0000
0111 1111 1111 1111
1111 1111 1111 1111 0
1

0 1

0 1 (NOT ) (AND
) (OR ) (XOR )

0 1 1 0
" 1 1 0"
" 1 1 0"
" 1 0 1 0"
ON/OFF

100 MB
100 MB

JPEG

xxxKB xxxMB B = Byte

1 8 256 0000
0000 - 1111 1111
compaction algorithm

RLE Huffman LZW

JPEG/MPEG

Huffman

JPEG
MPEG

MP3/RM/VCD/DVD /
≤50 ms / / / CPU/DSP

JPEG2000
MPEG-2/4

RLE
AAAAAABBCDDEEEEEF 17
RLE

1 17

17

*
AAAAAABBCDDEEEEEF 17 A6B2C1D2E5F1 12
12 / 17 = 70% 70%

* RLE(Run Length
Encoding, ) RLE
RLE

RLE

RLE RLE RLE


RLE RLE

14862 29065 199%

96062 38328 40%

EXE 24576 15198 62%

RLE

RLE
ABCDEFGHIJKLMNOPQRSTUVWXYZ 26 26
RLE
A1B1C1D1E1F1G1H1I1J1K1L1M1N1O1P1Q1R1S1T1U1V1W1X1Y1Z1 52
RLE

1 1 (8 )

A 100 Q 3
8 8 A Q
8 100 *8 +3 *8 = 824 A 2 Q 10
2 * 100 + 3 * 10 = 230

1 ( ) 11
( )
1
11 E 1 C
9 110101101 1 3
1 AAAAAABBCDDEEEEEF

00

AAAAAABBCDDEEEEEF A*6 +B*2 +C*1 +D*2 +E*5 +


F*1 + * 16 = 4 *6 +8 *2 +9 *1 +6 *2 +1 *5 +8 *1 +
2 * 16 = 106 = 14

14 / 17 = 82%

AAAAAABBCDDEEEEEF
AAAAAABBCDDEEEEEF A-F

A 6 0 1

E 5 1 1

B 2 10 2

D 2 11 2

C 1 100 3

F 1 101 3

1
2 3 100 3
1 0 0 E A A 10 0 B A 100 C
AAAAAABBCDDEEEEEF
000000000000 100100 110 101101 0101010101 111 40 =5 17
5 = 5 / 17 = 29%

14862 4119 28%

96062 9456 10%

EXE 24576 4652 19%


: BMP JPEG TIFF GIF

BMP Windows
JPEG
TIFF: " "
GIF 256

RLE

JPEG GIF

CPU soft disk


---

2000

hard disk
---

CPU

CPU
Windows
Windows 95/98

web
web web
web

WINDOWS
PAGEFILE.SYS

5MB
10MB CPU
swap

CPU
Windows

Page In Page Out Windows


4KB 4KB page

Page In Page Out

Windows page file


Windows 1-2

Windows MS-DOC 128kb


Windows 512MB

Page In Page Out

DLL
DLL Dynamic Link Library
Library DLL
DLL
MyFunc() A B
MyFunc() Static Link

DLL EXE DLL


MyFunc

DDL

Windows DLL DLL


DLL EXE
DLL

_stdcall
_stdcall C
_stdcall
_stdcall standard call( ) Windows DLL
_stdcall C
_stdcall C C C _stdcall C

C _stdcall

C Java C

1 //
2 void main(){
3 int a;
4 a = MyFunc(123,456);
5 }
6
7 //
8 int MyFunc(int a,int b){
9 ...
10 }

main MyFunc() main


MyFunc()

1 push 1C8h // 456( = 1C8h)


2 push 7Bh // 123( = 7Bh)
3 call @LTD+15 (MyFunc)(00401014) // MyFunc
4 add esp,8 //

C push pop
32 CPU 1 push 4 32
push 8 call
add esp,8 esp 8
8
C

_stdcall
CPU

Windows
Windows 512
Windows 1
512 1 =1 1KB 1 =2 2KB 4KB 8KB 16KB 32KB( 1 = 64
)

1 1

= +

wow

Windows Linux Unix Windows


Windows Windows 32 64

CPU
CPU
Graphic Processing Unit GPU
5GB

CPU
CPU

CPU CPU
(native code) C (
)

CPU

Windows CPU

CPU I/O

WIndows Windows
I/O Windows
Windows
API

AT Windows Unix Linux FreeBSD


Unix CPU
,

API(Application Programming Interface) Windows


Linux API API
API

API

Windows Linux API

API CPU

FreeBSD Port
“ CPU
” Unix FreeBSD

Unix FreeBSD Ports

Ports FTP

FreeBSD Ports

FreeBSD Ports
16000

FreeBSD C C FreeBSD

FTP( File Transfer Protocol)

Virtual Machine

Java
Java Java
Java

Java Java Java


Java CPU
Java (Java Virtual
Machine) Java Java
Linux

Java

Windows Windows Macintosh Macintosh


Java Java

BIOS

BIOS(Basic
Input/Output System) BIOS ROM
BIOS
CD-ROM

BIOS
OS OS OS

Microsoft Word
Microsoft Excel

Windows
= +

( )

ADD MOV

bug
Windows C
time() printf()

1 #include <stdio.h>
2 #include <time.h>
3
4 void main(){
5 //
6 time_t tm;
7
8 //
9 time(&tm);
10
11 //
12 printf("%s\n", ctime(&tm));
13 }

time_t tm time_t
time(&tm)
printf("%s\n" ctime(&tm))

CPU

time() printf()
IC I/O

(Real-time clock) IC
OS

time()
printf()

C Windows
Linux
1 #include <stdio.h>
2
3 void main(){
4
5 //
6 FILE *fp = fopen("MyFile.txt","w");
7
8 //
9 fputs(" ", fp);
10
11 //
12 fclose(fp);
13 }

C fputs() fclose()
I/O

fopen() MyFile.txt
w fputs() " " fp fclose()
fp

fp fp fopen()

fopen() fopen()
fputs() fclose() fclose()

Windows

Windows Windows
Windows Windows

Windows 32 64
API

WYSIWYG WYSIWYG What You See Is What You Get

32
32 Windows 32
MS-DOS 16 16 32
32 32 windows
32

C 8 char 16 short 32 long


long

64 64

API
Windows API API
Application Programming Interface ,

32 Windows API Win32 API


16 Win16 API Win64 API

API DLL API C C


API API MessageBox() Windows
user32.dll DLL

GUI
GUI(Graphical User Interface)
Linux

WYSIWYG
WYSIWYG Windows
WYSIWYG

WYSIWYG
Windows WYSIWYG

Windows

CPU
CPU

Windows ( )

(Plug-and-Play) (plug)
DLL DLL API
API

CPU ( ) C
CPU

add(addition)
cmp(compare)

C CPU
C
C
C

Borland C++ 5.5


: https://pan.baidu.com/s/19LqVICpn5GcV88thD2AnlA
:hz1u

https://wenku.baidu.com/view/22e2f418650e52ea55
1898ad.html

Windows

1 //
2 int AddNum(int a,int b){
3 return a + b;
4 }
5
6 // AddNum
7 void MyFunc(){
8 int c;
9 c = AddNum(123,456);
10 }

Sample4.c C .c

Windows Sample4.c

1 bcc32 -c -S Sample4.c

bcc32 Borland C++ -c -S

Sample4.asm
.asm Sample4.asm

1 .386p
2 ifdef ??version
3 if ??version GT 500H
4 .mmx
5 endif
6 endif
7 model flat
8 ifndef ??version
9 ?debug macro
10 endm
11 endif
12 ?debug S "Sample4.c"
13 ?debug T "Sample4.c"
14 _TEXT segment dword public use32 'CODE'
15 _TEXT ends
16 _DATA segment dword public use32 'DATA'
17 _DATA ends
18 _BSS segment dword public use32 'BSS'
19 _BSS ends
20 DGROUP group _BSS,_DATA
21 _TEXT segment dword public use32 'CODE'
22 _AddNum proc near
23 ?live1@0:
24 ;
25 ; int AddNum(int a,int b){
26 ;
27 push ebp
28 mov ebp,esp
29 ;
30 ;
31 ; return a + b;
32 ;
33 @1:
34 mov eax,dword ptr [ebp+8]
35 add eax,dword ptr [ebp+12]
36 ;
37 ; }
38 ;
39 @3:
40 @2:
41 pop ebp
42 ret
43 _AddNum endp
44 _MyFunc proc near
45 ?live1@48:
46 ;
47 ; void MyFunc(){
48 ;
49 push ebp
50 mov ebp,esp
51 ;
52 ; int c;
53 ; c = AddNum(123,456);
54 ;
55 @4:
56 push 456
57 push 123
58 call _AddNum
59 add esp,8
60 ;
61 ; }
62 ;
63 @5:
64 pop ebp
65 ret
66 _MyFunc endp
67 _TEXT ends
68 public _AddNum
69 public _MyFunc
70 ?debug D "Sample4.c" 20343 45835
71 end

1 _TEXT segment dword public use32 'CODE'


2 _TEXT ends
3 _DATA segment dword public use32 'DATA'
4 _DATA ends
5 _BSS segment dword public use32 'BSS'
6 _BSS ends
7 DGROUP group _BSS,_DATA
8
9 _AddNum proc near
10 _AddNum endp
11
12 _MyFunc proc near
13 _MyFunc endp
14
15 _TEXT ends
16 end

segment ends

3 _TEXT _DATA _BSS _TEXT


_DATA _BSS
Borland C++ Borland C++
_TEXT _DATA _BSS

1 _TEXT segment dword public use32 'CODE'


2 _TEXT ends
3 _DATA segment dword public use32 'DATA'
4 _DATA ends
5 _BSS segment dword public use32 'BSS'
6 _BSS ends
( segment ) segment
ends

group _BSS _DATA DGROUP

1 DGROUP group _BSS,_DATA

_AddNum _MyFun _TEXT segment _TEXT ends _AddNum _MyFun


_TEXT

1 _TEXT segment dword public use32 'CODE'


2 _TEXT ends

_AddNum proc _AddNum endp _MyFunc proc _MyFunc endp


AddNum MyFunc

1 _AddNum proc near


2 _AddNum endp
3
4 _MyFunc proc near
5 _MyFunc endp

_ Borland C++ C AddNum


_AddNum proc endp
(procedure) C

end

CPU +

Give me money
Give me money
Give me,money

CPU
CPU
CPU

CPU

CPU x86
x86 CPU

CPU

mov

mov mov
( )
([]) ([])

1 mov ebp,esp
2 mov eax,dword ptr [ebp+8]

mov ebp,esp esp ebp esp 100


ebp 100

mov eax,dword ptr [ebp+8] ebp +8


ebp

100 eax 100 + 8 dword ptr


double word pointer 4

push pop

stack
push pop
32 x86 CPU 1 push pop
32 4

C
MyFunc AddNum
MyFunc

1 _MyFunc proc near


2 push ebp ; ebp (1)
3 mov ebp,esp ; esp ebp (2)
4 push 456 ; 456 (3)
5 push 123 ; 123 (4)
6 call _AddNum ; AddNum (5)
7 add esp,8 ; esp + 8 (6)
8 pop ebp ; esp (7)
9 ret ; MyFunc (8)
10 _MyFunc endp

(1) (2) (7) (8) C AddNum


(3) - (6)
(3) (4) AddNum push C
AddNum(123,456) 456 123
C (5) call AddNum
AddNum
(6) call call ( (6) ) (
) push AddNum ret pop
(6)

(6) (456 123) pop


esp +8 ( 1 )
4 esp 4 2 8 pop
esp

Sample4.c

c MyFunc
AddNum c

AddNum

AddNum
Sample4.c AddNum

1 _AddNum proc near


2 push ebp -----------(1)
3 mov ebp,esp -----------(2)
4 mov eax,dword ptr[ebp+8] -----------(3)
5 add eax,dword ptr[ebp+12] -----------(4)
6 pop ebp -----------(5)
7 ret ----------------------------------(6)
8 _AddNum endp

ebp (1) (5) ebp

(2) esp ebp mov


esp esp ebp

(3) [ebp + 8] 1 123 eax pop


eax eax

(4) add eax 2 eax [ebp +


12] 2 456 C eax

(6) ret (6)


(Call _AddNum) AddNum

AddNum
C

1 //
2 int a1 = 1;
3 int a2 = 2;
4 int a3 = 3;
5 int a4 = 4;
6 int a5 = 5;
7
8 //
9 int b1,b2,b3,b4,b5;
10
11 //
12 void MyFunc(){
13 //
14 int c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;
15
16 //
17 c1 = 1;
18 c2 = 2;
19 c3 = 3;
20 c4 = 4;
21 c5 = 5;
22 c6 = 6;
23 c7 = 7;
24 c8 = 8;
25 c9 = 9;
26 c10 = 10;
27
28 //
29 a1 = c1;
30 a2 = c2;
31 a3 = c3;
32 a4 = c4;
33 a5 = c5;
34 b1 = c6;
35 b2 = c7;
36 b3 = c8;
37 b4 = c9;
38 b5 = c10;
39 }

Borland C++
1 _DATA segment dword public use32 'DATA'
2 align 4
3 _a1 label dword
4 dd 1
5 align 4
6 _a2 label dword
7 dd 2
8 align 4
9 _a3 label dword
10 dd 3
11 align 4
12 _a4 label dword
13 dd 4
14 align 4
15 _a5 label dword
16 dd 5
17 _DATA ends
18
19 _BSS segment dword public use32 'BSS'
20 align 4
21 _b1 label dword
22 db 4 dup(?)
23 align 4
24 _b2 label dword
25 db 4 dup(?)
26 align 4
27 _b3 label dword
28 db 4 dup(?)
29 align 4
30 _b4 label dword
31 db 4 dup(?)
32 align 4
33 _b5 label dword
34 db 4 dup(?)
35 _BSS ends
36
37 _TEXT segment dword public use32 'CODE'
38 _MyFunc proc near
39
40 push ebp
41 mov ebp,esp
42 add esp,-20
43 push ebx
44 push esi
45 mov eax,1
46 mov edx,2
47 mov ecx,3
48 mov ebx,4
49 mov esi,5
50 mov dword ptr [ebp-4],6
51 mov dword ptr [ebp-8],7
52 mov dword ptr [ebp-12],8
53 mov dword ptr [ebp-16],9
54 mov dword ptr [ebp-20],10
55 mov dword ptr [_a1],eax
56 mov dword ptr [_a2],edx
57 mov dword ptr [_a3],ecx
58 mov dword ptr [_a4],ebx
59 mov dword ptr [_a5],esi
60 mov eax,dword ptr [ebp-4]
61 mov dword ptr [_b1],eax
62 mov edx,dword ptr [ebp-8]
63 mov dword ptr [_b2],edx
64 mov ecx,dword ptr [ebp-12]
65 mov dword ptr [_b3],ecx
66 mov eax,dword ptr [ebp-16]
67 mov dword ptr [_b4],eax
68 mov edx,dword ptr [ebp-20]
69 mov dword ptr [_b5],edx
70 pop esi
71 pop ebx
72 mov esp,ebp
73 pop ebp
74 ret
75
76 _MyFunc endp
77 _TEXT ends

_DATA

1 _DATA segment dword public use32 'DATA'


2 ...
3 _DATA ends

_BSS

1 _BSS segment dword public use32 'BSS'


2 ...
3 _BSS ends

_TEXT Borland C++

1 _TEXT segment dword public use32 'CODE'


2 _MyFunc proc near
3 ...
4 _MyFunc endp
5 _TEXT ends
add A,B A B A

call A A

cmp A,B A B

inc A A +1

ige cmp

jl cmp

jle cmp

jmp cmp

mov A,B B A

pop A A

push A A

ret

xor A,B A B A

_DATA _a1 label dword _a1


_a1 _DATA 0
_a1 a1 (_) Borland C++
dd 1 4 1 dd define
double word 2 (word) 4

Borland C++ int 4 int a1 = 1 _a1 label


dword dd 1 a2 - a5 _a2 - _a5
2-5 4

_BSS b1 - b5 _b1 -
_b5 db 4dup(?) 4 ?
db(define byte) 1 1 db 4 dup(?) 4

db 4 dup(?) dd 4 4 1 db 4
(=4 ) 4
10
c1 - c10

_TEXT MyFunc MyFunc

Borland C++

1 mov eax,1
2 mov edx,2
3 mov ecx,3
4 mov ebx,4
5 mov esi,5

5 c1 - c5 1-5 eax edx ecx ebx esi x86 32


CPU

x86 CPU

c1 - c5
5 c6 - c10

1 mov dword ptr [ebp-4],6


2 mov dword ptr [ebp-8],7
3 mov dword ptr [ebp-12],8
4 mov dword ptr [ebp-16],9
5 mov dword ptr [ebp-20],10

add esp,-20 esp ( ) 20


c6 - c10 5 int 4 * 5 = 20
mov ebp,esp esp ebp
mov esp ebp esp
1 mov dword ptr [ebp-4],6
2 mov dword ptr [ebp-8],7
3 mov dword ptr [ebp-12],8
4 mov dword ptr [ebp-16],9
5 mov dword ptr [ebp-20],10

mov ebp, esp


esp esp [ebp - 4] [ebp - 8] [ebp - 12] [ebp
- 16] [ebp - 20] 20 5 4
mov dword ptr [ebp-4],6 (ebp
) 4 ([ebp - 4]) 6 4
for if
c

1 // MySub
2 void MySub(){
3 //
4
5 }
6
7 // MyFunc
8 void Myfunc(){
9 int i;
10 for(int i = 0;i < 10;i++){
11 // MySub
12 MySub();
13 }
14 }

i MySub

1 xor ebx, ebx ; 0


2 @4 call _MySub ; MySub
3 inc ebx ; ebx + 1
4 cmp ebx,10 ; ebx 10
5 jl short @4 ; 10 @4

C for (i = 0) (i < 10)


(i++) (cmp)
(jl)

MyFunc i i ebx for


i=0 xor ebx,ebx xor
XOR
ebx XOR
0 mov ebx,0 xor

XOR a b 1 a b
0

XOR 0 XOR 1
0 01010101 01010101 XOR
0

ebx call _MySub _MySub inc


ebx ebx +1 i++ ++ +1
i++ ++i

i++ i +1

++i +1

inc cmp cmp ebx,10


C i < 10 ebx 10
CPU

jl cmp ebx,10 jl
jump on less than( ) i 10 @4

1 i ^= i;
2 L4: MySub();
3 i++;
4 if(i < 10) goto L4;

i ^= i i i XOR MySub() L4
i i 10 MySub()

cmp C

1 // MySub1
2 void MySub1(){
3
4 //
5 }
6
7 // MySub2
8 void MySub2(){
9
10 //
11 }
12
13 // MySub3
14 void MySub3(){
15
16 //
17 }
18
19 // MyFunc
20 void MyFunc(){
21
22 int a = 123;
23 //
24 if(a > 100){
25 MySub1();
26 }
27 else if(a < 50){
28 MySub2();
29 }
30 else
31 {
32 MySub3();
33 }
34
35 }

C Borland C++

1 _MyFunc proc near


2 push ebp
3 mov ebp,esp
4 mov eax,123 ; 123 eax
5 cmp eax,100 ; eax 100
6 jle short @8 ; 100 @8
7 call _MySub1 ; MySub1
8 jmp short @11 ; @11
9 @8:
10 cmp eax,50 ; eax 50
11 jge short @10 ; 50 @10
12 call _MySub2 ; MySub2
13 jmp short @11 ; @11
14 @10:
15 call _MySub3 ; MySub3
16 @11:
17 pop ebp
18 ret
19 _MyFunc endp

jle(jump on less or equal)


jge(jump on greater or equal)
jmp cmp

C
Java Java native
C Java
bug
CPU
1 //
2 int counter = 100;
3
4 // MyFunc1()
5 void MyFunc(){
6 counter *= 2;
7 }
8
9 // MyFunc2()
10 void MyFunc2(){
11 counter *= 2;
12 }

counter C MyFunc1() MyFunc2() counter


counter counter
MyFunc1 MyFunc2 counter 100 * 2 * 2 =
400 counter 200

1 mov eax,dword ptr[_counter] ; counter eax


2 add eax,eax ; eax 2
3 mov dword ptr[_counter],eax ; eax counter

MyFun1 counter 100 200 counter MyFun2


counter 100 200

bug C
C Java

C Java
Windows

Windows Windows
Windows API API
DLL

API

Windows API TextOut TextOut


C

1 BOOL TextOut{
2 HDC hdc, //
3 int nXStart, // x
4 int nYStart, // y
5 LPCTSTR lpString, //
6 int cbString //
7 }
TextOut Windows Windows
Windows Windows CPU

Windows TextOut API C printf


printf

IN OUT
Windows IN OUT

IN OUT

IN OUT

IN OUT CPU

IO
IC
IC IC IO
IO Input/Output I/O I/O
(port)
IO
CPU IO

I/O IC I/O
I/O

I/O IN OUT CPU

CPU

IN OUT

C C
_asm{ } C

AT 61H H IN
2 ON OUT
2 OFF

ON 1 OFF 0 ON
ON 1 0 OR 2 1
03H OR 03H 8 00000011 6
0 OR 03H OR OFF
OFF 0 1 AND 2 0
FCH AND FCH 0FCH 0
A-F 0FCH 8
11111100 6 1 AND 0FCH
OR

1 void main(){
2
3 //
4 int i;
5
6 //
7 _asm{
8 IN EAX, 61H
9 OR EAX, 03H
10 OUT 61H, EAX
11 }
12
13 //
14 for(i = 0;i < 1000000;i++);
15
16 //
17 _asm{
18 IN EAX, 61H
19 AND EAX, 0FCH
20 OUT 61H, EAX
21 }
22 }

main C _asm{}
for

IN EAX 61H( ) 61H


CPU EAX OR EAX 03H EAX 2 ON
OUT 61H EAX EAX 61 EAX
32 8 8 OR AND

100
100

IN EAX 61H 61H


CPU EAX AND EAX 0FCH EAX 2 OFF
OUT 61H EAX EAX 61

IRQ(Interrupt Request) IRQ


( ) ( )

I/O CPU
I/O IRQ
06 06 BIOS

BIOS(Basic Input Output System): ROM

CPU I/O
CPU IC
CPU
CPU
CPU
CPU

CPU
CPU
CPU
DMA
I/O
DMA(Direct Memory Access) DMA CPU
DMA DMA
CPU DMA

DMA DMA

I/O IRQ DMA 3 IRQ DMA


I/O
IRQ DMA DMA
IRQ DMA

VRAM(Video RAM) VRAM


BIOS

MS-DOS VRAM
VRAM GPU Graphics Processing Unit
windows VRAM
VRAM

DMA

You might also like