PC Assembly Language

Size: px
Start display at page:

Download "PC Assembly Language"

Transcription

1 PC Paul A. Carter :

2 Copyright c 2001, 2002, 2003, 2004 by Paul Carter ( )

3 i CPU CPU 80x C

4 If While Do while : AND OR XOR NOT TEST C C C Big Little Endian Little Big Endian

5 CALL RET C C C / REP REPx IEEE

6 C s C C A 80x A A

7 Pascal C C++ PC 1981 PC 8086! ( Windows Linux ) PC 3. PC / NASM DJGPP C/C++ Linux Windows Borland Microsoft C/C++ NASM / i

8 ii John S. Fine Simon Tatham Julian Hall NASM DJGPP C/C++DJ Delorie DJGPP GNU gcc Donald Knuth TEX L A TEX 2ε Richard Stallman ( ) Linus Torvalds (Linux ) John S. Fine Marcelo Henrique Pinto de Almeida Sam Hopkins Nick D Imperio Jeremiah Lawrence Ed Beroset Jerry Gembarowski Ziqiang Peng Eno Compton Josh I Cates Mik Mifflin Luke Wallis Gaku Ueda Brian Heward Chad Gorshing F. Gotti Bob Wilkinson Markus Koegel Louis Taber Dave Kiddell Eduardo Horowitz

9 iii Sébastien Le Ray Nehal Mistry Jianyue Wang Jeremias Kleer Marc Janicki NASM DJGPP Linux (The Art of Assembly) USENET Intel comp.lang.asm.x86 /Pentium4/documentation.htm. WWW:

10 iv

11 1 1.1 ( 10) ( 2) (0-9) = (0 1) 2 ( ) = = = ( : ) = 123 r 4 1

12 : c c c c 1.1: (c ) = r (lsb) (msb) ( hex) A B C D E F A 10 B BD 16 =

13 1.1 3 Decimal Binary 25 2 = 12 r = 1100 r = 6 r = 110 r = 3 r = 11 r = 1 r = 1 r = 0 r = 0 r = : = 36 r = 2 r = 0 r = 24D : = = D D : 2

14 4 1 word( ) double word( ) quad word( ) paragraph( ) : A 7 E FF ( 2 10 = ) ( 2 20 = ) ( 2 30 = ) Address Memory 2A 45 B8 20 8F CD 12 2E 1.4: PC 1.2 ASCII ( ) ASCII Unicode ASCII Unicode ( ) ASCII (65 10 ) A Unicode ASCII Unicode ASCII 3 ASCII 7 128

15 CPU (CPU) CPU CPU CPU CPU CPU CPU CPU CPU CPU Mac IBM PC ( GHz ) 1.5 GHz 1.5 GHz 4 ( ) CPU 1.5 GHz CPU CPU 80x86 IBM PC Intel 80x86 ( ) CPU CPU : CPU PC CPU 16 AX BX CX DX SI DI BP SP CS DS SS ES IP FLAGS 1M 64K 80286: CPU AT PC 8088/ M 64K 4 CPU CPU

16 6 1 AX AH AL 1.5: AX 80386: CPU (EAX EBX ECX EDX ESI EDI EBP ESP EIP) 16 FS GS 32 4G 4G 80486/Pentium/Pentium Pro: 80x86 Pentium MMX: Pentium MMX ( ) Pentium II: MMX Pentium (Pentium III Pentium II ) CPU 4 16 AX BX CX DX 8 AX AH AL 1.5 AH AX ( )8 AL AX 8 AH AL AX AX AH AL 16 SI DI 8 16 BP SP 16 CS DS SS ES CS DS SS ES ES (IP) CS CPU IP FLAGS 0 Z 1 0 FLAGS FLAGS

17 AX 32 AX 16 EAX 32 AX EAX 16 AL AX(EAX) 8 EAX 16 EBX ECX EDX ESI EDI BP EBP SP ESP FLAGS EFLAGSEFLAGS IP EIP 32 ( ) FS GS ( ES ) CPU 80x M (2 20 ) DOS640K FFFFF ( ) BIOS Intel (selector) 1M 16 (offset) selector + offset C: C ( 1.2) 64K (16 ) 64K CS 64K (segment) CS DS

18 C: D: E: B: ( ) PC CPU 64K G 4G 2. 4K Windows 3.x Windows 9X Windows NT/2000/XP OS/2 Linux 32

19 ( ) CPU ( ) I/O ( CD-ROM ) CPU DOS API( ) ( Windows UNIX) C 5 ( CPU ) CPU 80x86 ( ) EAX EBX EAX 03 C ( ) add eax, ebx 5

20 10 1 add mnemonic( ) operand(s)( ) CPU Netwide Assembler NASM Internet ( URL ) Microsoft Assembler(MASM) Borland Assembler (TASM) MASM/TASM NASM (0 3 ) : CPU : : ( ) : MOV ( ) mov dest ( ), src( ) src dest AX BL ( )

21 mov eax, 3 ; 3 EAX (3 ) mov bx, ax ; AX BX ADD add eax, 4 ; eax = eax + 4 add al, ah ; al = al + ah SUB sub bx, 10 ; bx = bx - 10 sub ebx, edi ; ebx = ebx - edi INC DEC INC DEC ADD SUB inc ecx ; ecx++ dec dl ; dl CPU NASM C C NASM % C # equ equ symbol equ value

22 12 1 B W D Q T 1.3: RESX DX %define C #define C %define SIZE 100 mov eax, SIZE SIZE MOV RESX X 1.3 ( ) DX X RESX L1 db 0 ; L1 0 L2 dw 1000 ; L L3 db b ; ( 53) L4 db 12h ; 12( 18) L5 db 17o ; 17( 15) L6 dd 1A92h ; 1A92 L7 resb 1 ;1 L8 db "A" ; ASCII A(65) L2 L1

23 L9 db 0, 1, 2, 3 ; 4 L10 db "w", "o", "r", d, 0 ; "word" C L11 db word, 0 ; L10 DD 6 DQ NASM TIMES L12 times 100 db 0 ; L13 resw 100 ; 100 ( ) ([]) * C (MASM/TASM ) mov al, [L1] ; L1 AL 2 mov eax, L1 ; EAX = L1 3 mov [L1], ah ; AH L1 4 mov eax, [L6] ; L6 EAX 5 add eax, [L6] ; EAX = EAX + L6 6 add [L6], eax ; L6 = L6 + EAX 7 mov al, [L6] ; L6 AL 7 NASM ( ) C C mov [L6], 1 ; 1 L6 operation size not specified( ) 1 mov dword [L6], 1 ; 1 L6 1 L6 BYTE( ) WORD( ) QWORD( ) TWORD( ) 7 6 C float 7 TWORD

24 14 1 print int print char print string print nl read int read char EAX ASCII AL EAX C ( : null ) EAX ASCII EAX 1.4: I/O C I/O ( ) C C I/O C ( ) I/O C 1.4 EAX NASM %include I/O 8 : %include "asm_io.inc" EAX CALL CALL call I/O CPU asm io.inc 8 asm io.inc ( asm io.inc asm io )

25 dump regs dump mem dump stack dump math dump regs ( ) stdout( ) FLAGS 9 1 ZF 0 dump regs dump mem ASCII ( ) ( dump regs ) ( ) 16 dump stack CPU ( 4 ) dump regs EBP EBP dump math dump regs C 9 2

26 int main() 2 { 3 int ret status ; 4 ret status = asm main(); 5 return ret status ; 6 } : driver.c 1.6 C asm main C C C C I/O C I/O (printf ) 1 ; : first.asm first.asm 2 ; 3 ; 4 ; 5 ; djgpp 6 ; nasm -f coff first.asm 7 ; gcc -o first first.o driver.c asm_io.o 8 9 %include "asm_io.inc" 10 ; 11 ; 12 ; 13 segment.data 14 ; 15 ; 16 ; 17 prompt1 db "Enter a number: ", 0 ; 18 prompt2 db "Enter another number: ", 0 19 outmsg1 db "You entered ", 0 20 outmsg2 db " and ", 0 21 outmsg3 db ", the sum of these is ", ;

27 ;.bss 25 ; 26 segment.bss 27 ; 28 ; 29 ; 30 input1 resd 1 31 input2 resd ; 34 ;.text 35 ; 36 segment.text 37 global _asm_main 38 _asm_main: 39 enter 0,0 ; 40 pusha mov eax, prompt1 ; 43 call print_string call read_int ; input1 46 mov [input1], eax ; mov eax, prompt2 ; 49 call print_string call read_int ; input2 52 mov [input2], eax ; mov eax, [input1] ; eax = input1 55 add eax, [input2] ; eax = eax + input2 56 mov ebx, eax ; ebx = eax dump_regs 1 ; 59 dump_mem 2, outmsg1, 1 ; 60 ; 61 ; 62 ; 63 mov eax, outmsg1 64 call print_string ; 65 mov eax, [input1]

28 call print_int ; input1 67 mov eax, outmsg2 68 call print_string ; 69 mov eax, [input2] 70 call print_int ; input2 71 mov eax, outmsg3 72 call print_string ; 73 mov eax, ebx 74 call print_int ; (ebx) 75 call print_nl ; popa 78 mov eax, 0 ; C 79 leave 80 ret first.asm 13 (.data) C null (ASCII 0) 0 0 bss (.bss 26 ) UNIX.text (38 ) C C C C C ( ) ( DOS/Windows linux C C ) 37 (global) asm main C global asm io print int et.al. first.asm GNU 10 DJGPP C/C++ 11 Internet 386 PC 10 GNU ( 11

29 DOS Windows 95/98 NT COFF (Common Object File Format ) nasm -f coff ( ) o Linux C GNU Linux Linux ELF(Executable and Linkable Format ) Linux -f elf o Borland C/C++ OMF Borland -f obj obj OMF 13 segment bss 26 segment text 36 segment 36 DATA public align=4 class=data use32 BSS public align=4 class=bss use32 TEXT public align=1 class=code use32 group DGROUP BSS DATA C/C++ OMF Win32 ( OMF Win32 )Win32 DJGPP Linux -f win32 obj nasm -f object-format first.asm object-format coff elf obj win32 C ( Linux Borland ) C C driver.c DJGPP gcc -c driver.c -c Linux Borland Microsoft

30 C C C DJGPP : gcc -o first driver.o first.o asm io.o first.exe( Linux first) Borland bcc32 first.obj driver.obj asm io.obj Borland first.exe gcc -o first driver.c first.o asm io.o gcc driver.c l listing-file nasm ( ) ( ) E E- prompt1 db "Enter a number: ", D A E E6F- prompt2 db "Enter another number: ", A E756D A2000 ( ) ASCII ( ) ( 1.4.5) text ( )

31 C A1[ ] mov eax, [input1] [ ] add eax, [input2] C3 mov ebx, eax 94 input1 ( ) mov ( A1) 0 input1 bss bss 96 Big Little Endian 95 input2 4( ) big endian little endian Big endian Endian indian ( ) IBM RISC Motorola big endian Intel little endian CPU 1. ( ) 2. Endian ( ) Endian

32 22 1 skel.asm 1 %include "asm_io.inc" 2 segment.data 3 ; 4 ; 5 ; 6 7 segment.bss 8 ; 9 ; bss 10 ; segment.text 13 global _asm_main 14 _asm_main: 15 enter 0,0 ; 16 pusha ; 19 ; text 20 ; 21 ; popa 24 mov eax, 0 ; 25 leave 26 ret skel.asm 1.7:

33 : ( ) ( C8) ( ) ( ) 0 ( ) 0 CPU CPU 23

34 24 2 ( 1 ) (+56) (+0) ( 0) F F C (56) ( ) ( ) 0 ( ) c

35 F FE -1 FF 2.1: c ( ) , , , 767 7FFF 32, , FF80-1 FFFF CPU ( ) FF C C mov ax, 0034h ; ax = 52 ( ) mov cl, al ; cl = ax AX 0134h ( 308) CL 34h AX FFFFh ( 1) CL FFh ( 1) AX

36 , 0 FF FF FF ( ) 00FF ( 1) FFFF 0. FF 00FF FF 1 1 FFFF 5A ( 90) 005A MOV 0 AL AX mov ah, 0 ; 8 0 MOV AX EAX MOV EAX MOVZX ( ) ( ) 8 16 ( ) movzx eax, ax ; ax eax movzx eax, al ; al eax movzx ax, al ; al ax movzx ebx, ax ; ax ebx MOV 8086 CBW (Convert Byte to Word( )) AL AX CWD (Convert Word to Double word( )) AX DX:AX DX:AX DX AX DX 16 AX ( ) CWDE (Convert Word to Double word Extended(

37 unsigned char uchar = 0xFF; 2 signed char schar = 0xFF; 3 int a = (int) uchar; / a = 255 (0x000000FF) / 4 int b = (int) schar ; / b = 1 (0xFFFFFFFF) / char ch; while( (ch = fgetc(fp))!= EOF ) { / ch / } 2.1: 2.2: )) AX EAX CDQ (Convert Double word to Quad word( )) EAX EDX:EAX (64!). MOVSX MOVZX C C C ANSI C char (int ) a ( MOVZX) 4 b ( MOVSX) 2.1 C bug 2.2 fgetc() : int fgetc( FILE * ); : int char ( 0 int ) EOF 1 fgetc() int char ( xx) EOF ( FFFFFFFF) 2.2 fgetc() int char C int char ( ) FF FFFFFFFF FF while FF char 2 ch EOF EOF int 1 ch int 1 EOF!

38 char FF FF EOF (FFFFFFFF) char FF FFFFFFFF FF ch int char 2 ch add sub FLAGS overflow( ) carry flag( ) add sub 002C 44 + FFFF + ( 1) 002B 43 MUL IMUL MUL IMUL FF ( FE01) ( 0001) mul source source AL 16 AX 16 AX 32 2

39 dest source1 source2 reg/mem8 AX = AL*source1 reg/mem16 DX:AX = AX*source1 reg/mem32 EDX:EAX = EAX*source1 reg16 reg/mem16 dest *= source1 reg32 reg/mem32 dest *= source1 reg16 immed8 dest *= immed8 reg32 immed8 dest *= immed8 reg16 immed16 dest *= immed16 reg32 immed32 dest *= immed32 reg16 reg/mem16 immed8 dest = source1*source2 reg32 reg/mem32 immed8 dest = source1*source2 reg16 reg/mem16 immed16 dest = source1*source2 reg32 reg/mem32 immed32 dest = source1*source2 2.2: imul DX:AX 32 EAX EDX:EAX IMUL MUL imul imul dest ( ), source1( 1) dest ( ), source1( 1), source2( 2) 2.2 DIV IDIV div source 8 AX AL AH 16 DX:AX AX DX 32 EDX:EAX EAX EDX IDIV IMUL IDIV 0, DX EDX NEG math.asm

40 %include "asm_io.inc" 2 segment.data ; 3 prompt db "Enter a number: ", 0 4 square_msg db "Square of input is ", 0 5 cube_msg db "Cube of input is ", 0 6 cube25_msg db "Cube of input times 25 is ", 0 7 quot_msg db "Quotient of cube/100 is ", 0 8 rem_msg db "Remainder of cube/100 is ", 0 9 neg_msg db "The negation of the remainder is ", segment.bss 12 input resd segment.text 15 global _asm_main 16 _asm_main: 17 enter 0,0 ; 18 pusha mov eax, prompt 21 call print_string call read_int 24 mov [input], eax imul eax ; edx:eax = eax * eax 27 mov ebx, eax ; ebx 28 mov eax, square_msg 29 call print_string 30 mov eax, ebx 31 call print_int 32 call print_nl mov ebx, eax 35 imul ebx, [input] ; ebx *= [input] 36 mov eax, cube_msg 37 call print_string 38 mov eax, ebx 39 call print_int 40 call print_nl imul ecx, ebx, 25 ; ecx = ebx*25

41 mov eax, cube25_msg 44 call print_string 45 mov eax, ecx 46 call print_int 47 call print_nl mov eax, ebx 50 cdq ; edx 51 mov ecx, 100 ; 52 idiv ecx ; edx:eax / ecx 53 mov ecx, eax ; ecx 54 mov eax, quot_msg 55 call print_string 56 mov eax, ecx 57 call print_int 58 call print_nl 59 mov eax, rem_msg 60 call print_string 61 mov eax, edx 62 call print_int 63 call print_nl neg edx ; 66 mov eax, neg_msg 67 call print_string 68 mov eax, edx 69 call print_int 70 call print_nl popa 73 mov eax, 0 ; C 74 leave 75 ret math.asm ADD SUB ( ) ADC SBB ADC

42 32 2 SBB operand1 = operand1 + carry flag + operand2 operand1 = operand1 - carry flag - operand2 EDX:EAX EBX:ECX 64 EDX:EAX : 1 add eax, ecx ; 32 2 adc edx, ebx ; 32 EDX:EAX EBX:ECX: 1 sub eax, ecx ; 32 2 sbb edx, ebx ; 32 ( 2.2) ( ) ADC CLC (CLear Carry( )) 0, 0, ADD ADC 2.2 ( if while ) goto ( ) FLAGS 80x86 CMP FLAGS CMP FLAGS SUB CMP ( FLAGS ) (zero flag(zf)) (carry flag(cf)) 0 (1) cmp vleft, vright

43 vleft - vright CMP 0 vleft = vright ZF ( 1) CF ( 0) vleft > vright ZF CF ( ) vleft < vright ZF CF ( ) (zero flag (ZF)) (overflow flag(of)) (sign flag (SF)) vleft > vright ( ) vleft = vright ZF ( ) vleft > vright ZF SF = OF vleft < vright ZF SF OF FLAGS CMP goto goto FLAGS JMP (jump ) JMP jump SHORT 128 ( EIP) JMP SHORT NEAR , JMP WORD FAR 386 SF = OF SF = OF = 0 ( ) SF = OF = 1

44 34 2 JZ JNZ JO JNO JS JNS JC JNC JP JNP ZF ZF OF OF SF SF CF CF PF PF 2.3: FLAGS 2.3 (PF (parity flag) 8 1 ) : if ( EAX == 0 ) EBX = 1; else EBX = 2; 1 cmp eax, 0 ; ( eax - 0 = 0 ZF ) 2 jz thenblock ; ZF thenblock 3 mov ebx, 2 ; IF ELSE 4 jmp next ; IF THEN 5 thenblock: 6 mov ebx, 1 ; IF THEN 7 next: 2.3 if ( EAX >= 5 ) EBX = 1; else EBX = 2;

45 JE vleft = vright JE vleft = vright JNE vleft vright JNE vleft vright JL, JNGE vleft < vright JB, JNAE vleft < vright JLE, JNG vleft vright JBE, JNA vleft vright JG, JNLE vleft > vright JA, JNBE vleft > vright JGE, JNL vleft vright JAE, JNB vleft vright 2.4: EAX 5 ZF SF OF ( EAX ): 1 cmp eax, 5 2 js signon ; SF = 1 signon 3 jo elseblock ; OF = 1 SF = 0 elseblock 4 jmp thenblock ; SF = 0 OF = 0 thenblock 5 signon: 6 jo thenblock ; SF = 1 OF = 1 thenblock 7 elseblock: 8 mov ebx, 2 9 jmp next 10 thenblock: 11 mov ebx, 1 12 next: 80x (JE JNE) ( JE JZ JNE JNZ ) JL (jump less than) JNGE (jump not greater than or equal to) x < y = not(x y) A B L G 1 cmp eax, 5 2 jge thenblock 3 mov ebx, 2 4 jmp next 5 thenblock: 6 mov ebx, 1 7 next:

46 x86 for LOOP ECX ECX 0 LOOPE, LOOPZ ECX (FLAGS ) ECX 0 ZF = 1 LOOPNE, LOOPNZ ECX (FLAGS ) ECX 0 ZF = 0 sum = 0; for( i=10; i >0; i ) sum += i; : 1 mov eax, 0 ; eax (sum) 2 mov ecx, 10 ; ecx i 3 loop_start: 4 add eax, ecx 5 loop loop_start If : if ( ) then block ; else else block ; : 1 ; FLAGS 2 jxx else_block ; xx 3 ; then 4 jmp endif 5 else_block: 6 ; else 7 endif:

47 2.4 : 37 else else block endif 1 ; FLAGS 2 jxx endif ; xx 3 ; then 4 endif: 1 while: While while while( ) { ; } 2 ; FLAGS 3 jxx endwhile ; xx 4 ; 5 jmp while 6 endwhile: 1 do: Do while do while do { ; } while( ); 2 ; 3 ; FLAGS 4 jxx do ; xx 2.4 : 1

48 unsigned guess; / / 2 unsigned factor ; / / 3 unsigned limit ; / / 4 5 printf ( Find primes up to: ); 6 scanf( %u, &limit); 7 printf ( 2\n ); / / 8 printf ( 3\n ); 9 guess = 5; / / 10 while ( guess <= limit ) { 11 / / 12 factor = 3; 13 while ( factor factor < guess && 14 guess % factor!= 0 ) 15 factor += 2; 16 if ( guess % factor!= 0 ) 17 printf ( %d\n, guess); 18 guess += 2; / / 19 } 2.3: C : 1 %include "asm_io.inc" 2 segment.data prime.asm 3 Message db "Find primes up to: ", segment.bss 6 Limit resd 1 ; 7 Guess resd 1 ; 8 9 segment.text 10 global _asm_main 11 _asm_main: 12 enter 0,0 ; 13 pusha

49 2.4 : mov eax, Message 16 call print_string 17 call read_int ; scanf("%u", & limit ); 18 mov [Limit], eax mov eax, 2 ; printf("2\n"); 21 call print_int 22 call print_nl 23 mov eax, 3 ; printf("3\n"); 24 call print_int 25 call print_nl mov dword [Guess], 5 ; Guess = 5; 28 while_limit: ; while ( Guess <= Limit ) 29 mov eax,[guess] 30 cmp eax, [Limit] 31 jnbe end_while_limit ; jnbe mov ebx, 3 ; ebx factor = 3; 34 while_factor: 35 mov eax,ebx 36 mul eax ; edx:eax = eax*eax 37 jo end_while_factor ; eax 38 cmp eax, [Guess] 39 jnb end_while_factor ; if!(factor*factor < guess) 40 mov eax,[guess] 41 mov edx,0 42 div ebx ; edx = edx:eax % ebx 43 cmp edx, 0 44 je end_while_factor ; if!(guess % factor!= 0) add ebx,2 ; factor += 2; 47 jmp while_factor 48 end_while_factor: 49 je end_if ; if!(guess % factor!= 0) 50 mov eax,[guess] ; printf("%u\n") 51 call print_int 52 call print_nl 53 end_if: 54 add dword [Guess], 2 ; guess += 2 55 jmp while_limit 56 end_while_limit:

50 popa 59 mov eax, 0 ; C 60 leave 61 ret prime.asm

51 3 3.1 ( ) ( ) : 0 SHL SHR CL 1 mov ax, 0C123H 2 shl ax, 1 ; ax = 8246H, CF = 1 3 shr ax, 1 ; ax = 4123H, CF = 0 4 shr ax, 1 ; ax = 2091H, CF = 1 5 mov ax, 0C123H 6 shl ax, 2 ; ax = 048CH, CF = 1 7 mov cl, 3 8 shr ax, cl ; ax = 0091H, CF = 1 41

52 ( 11) ( 22) 2 2 4(2 2 ), 2 8(2 3 3 MUL DIV FFFF( 1) 7FFF +32, 767! SAL (Shift Arithmetic Left) - SHL SHL SAR (Shift Arithmetic Right) - ( ) ( 1, 1) 7 1 mov ax, 0C123H 2 sal ax, 1 ; ax = 8246H, CF = 1 3 sal ax, 1 ; ax = 048CH, CF = 1 4 sar ax, 2 ; ax = 0123H, CF = ROL ROR

53 mov ax, 0C123H 2 rol ax, 1 ; ax = 8247H, CF = 1 3 rol ax, 1 ; ax = 048FH, CF = 1 4 rol ax, 1 ; ax = 091EH, CF = 0 5 ror ax, 2 ; ax = 8247H, CF = 1 6 ror ax, 1 ; ax = C123H, CF = 1 RCL RCR AX 17 AX 1 mov ax, 0C123H 2 clc ; (CF = 0) 3 rcl ax, 1 ; ax = 8246H, CF = 1 4 rcl ax, 1 ; ax = 048DH, CF = 1 5 rcl ax, 1 ; ax = 091BH, CF = 0 6 rcr ax, 2 ; ax = 8246H, CF = 1 7 rcr ax, 1 ; ax = C123H, CF = EAX on ( 1) 1 mov bl, 0 ; bl ON 2 mov ecx, 32 ; ecx 3 count_loop: 4 shl eax, 1 ; 5 jnc skip_inc ; CF == 0 skip_inc 6 inc bl 7 skip_inc: 8 loop count_loop EAX ( EAX 0) EAX rol eax, AND OR XOR NOT

54 44 3 X Y X AND Y : AND AND : AND AND AND AL BL AND AND mov ax, 0C123H 2 and ax, 82F6H ; ax = 8022H OR OR mov ax, 0C123H 2 or ax, 0E831H ; ax = E933H XOR XOR mov ax, 0C123H 2 xor ax, 0E831H ; ax = 2912H

55 X Y X OR Y : OR X Y X XOR Y : XOR NOT NOT ( AND) NOT mov ax, 0C123H 2 not ax ; ax = 3EDCH NOT NOT FLAGS TEST TEST AND FLAGS ( CMP FLAGS) 0 ZF mov ax, 0C123H 2 or ax, 8 ; 3 ax = C12BH 3 and ax, 0FFDFH ; 5 ax = C10BH 4 xor ax, 8000H ; 31 ax = 410BH

56 46 3 X NOT X : NOT i i i 2 i ( i on ) OR i off AND 2 i XOR 3.5: 5 or ax, 0F00H ; ax = 4F0BH 6 and ax, 0FFF0H ; ax = 4F00H 7 xor ax, 0F00FH ; ax = BF0FH 8 xor ax, 0FFFFH ; ax = 40F0H AND 2 2 i 2 i 1 AND 0 2 i 1 1 AND mov eax, 100 ; 100 = 64H 2 mov ebx, FH ; = 16-1 = 15 F 3 and ebx, eax ; ebx = = 4 CL EAX ( ) BH 1 mov cl, bh ; OR 2 mov ebx, 1 3 shl ebx, cl ; cl 4 or eax, ebx ; 1 mov cl, bh ; AND 2 mov ebx, 1 3 shl ebx, cl ; cl 4 not ebx ; 5 and eax, ebx ;

57 mov bl, 0 ; bl ON 2 mov ecx, 32 ; ecx 3 count_loop: 4 shl eax, 1 ; 5 adc bl, 0 ; bl 6 loop count_loop 3.3: ADC 80x86 xor eax, eax ; eax = 0 XOR 0 MOV 3.3 CPU EAX on INC 3.3 ADC SETxx FLAGS 0 1 SET SETxx 1, 0 setz al ; AL = ZF 1 0 CMP

58 ; file: max.asm 2 %include "asm_io.inc" 3 segment.data 4 5 message1 db "Enter a number: ",0 6 message2 db "Enter another number: ", 0 7 message3 db "The larger number is: ", segment.bss 11 input1 resd 1 ; segment.text 14 global _asm_main 15 _asm_main: 16 enter 0,0 ; 17 pusha mov eax, message1 ; 20 call print_string 21 call read_int ; 22 mov [input1], eax mov eax, message2 ; 25 call print_string 26 call read_int ; ( eax ) xor ebx, ebx ; ebx = 0 29 cmp eax, [input1] ; 30 setg bl ; ebx = (input2 > input1)? 1 : 0 31 neg ebx ; ebx = (input2 > input1)? 0xFFFFFFFF : 0 32 mov ecx, ebx ; ecx = (input2 > input1)? 0xFFFFFFFF : 0 33 and ecx, eax ; ecx = (input2 > input1)? input2 : 0 34 not ebx ; ebx = (input2 > input1)? 0 : 0xFFFFFFFF 35 and ebx, [input1] ; ebx = (input2 > input1)? 0 : input1 36 or ecx, ebx ; ecx = (input2 > input1)? input2 : input mov eax, message3 ; 39 call print_string 40 mov eax, ecx 41 call print_int

59 3.4 C call print_nl popa 45 mov eax, 0 ; C 46 leave 47 ret 30 SETG BL 1, 0 31 EBX NEG ( EBX 0 ) EBX 0, EBX 1, -1 0xFFFFFFFF DEC DEC NEG 0 0xFFFFFFFF NEG 3.4 C C C AND & 1 OR NOT ~ C << >> << >> ( int) C 1 short int s; / short int 16 / 2 short unsigned u; 3 s = 1; / s = 0xFFFF ( ) / 4 u = 100; / u = 0x0064 / 5 u = u 0x0100; / u = 0x0164 / 6 s = s & 0xFFF0; / s = 0xFFF0 / 7 s = s ˆ u; / s = 0xFE94 / 8 u = u << 3; / u = 0x0B20 ( ) / 9 s = s >> 2; / s = 0xFFA5 ( ) / 1 && &!

60 50 3 S IRUSR S IWUSR S IXUSR S IRGRP S IWGRP S IXGRP S IROTH S IWOTH S IXOTH 3.6: POSIX C C C x *= 2 API 2 ( POSIX 3 Win32) POSIX user ( owner ) group( ) others( ) / C POSIX ( 3.6) chmod 4 owner group others chmod( foo, S IRUSR S IWUSR S IRGRP ); POSIX stat chmod others owner 1 struct stat file stats ; / stat() / 2 stat( foo, & file stats ); / file stats.st mode / 3 chmod( foo, ( file stats.st mode & S IWOTH) S IRUSR); 2 Application Programming Interface 3 IEEE UNIX 4 mode t mode t

61 3.5 BIG LITTLE ENDIAN 51 unsigned short word = 0x1234; / sizeof(short) == 2 / unsigned char p = (unsigned char ) &word; if ( p[0] == 0x12 ) printf ( Big Endian Machine\n ); else printf ( Little Endian Machine\n ); 3.4: Endian 3.5 Big Little Endian big little endian endian Big endian Little endian ( ) x86 little endian big endian little endian little endian Intel CPU ( ) CPU little endian CPU ( ) CPU 2 AX AH AL CPU AH AL CPU AH AL mov AX AL AH CPU AH CPU ( ) CPU ( )CPU 3.4 C CPU Endian p word word p[0] CPU Endian

62 unsigned invert endian ( unsigned x ) 2 { 3 unsigned invert ; 4 const unsigned char xp = (const unsigned char ) &x; 5 unsigned char ip = (unsigned char ) & invert ; 6 7 ip [0] = xp[3]; / / 8 ip [1] = xp[2]; 9 ip [2] = xp[1]; 10 ip [3] = xp[0]; return invert ; / / 13 } 3.5: invert endian Function UNICODE Endian UNICODE Endian Endian Little Big Endian CPU Endian ( ) ASCII Endian TCP/IP big endian ( ). TCP/IP Endian C htonl() ( ) ntohl() 5 big endian Endian Endian W. Richard Steven UNIX Network Programming 3.5 Endian C 486 BSWAP 32 bswap edx ; edx 16 XCHG 8 16 xchg ah,al ; ax 5 Endian big little little big

63 int count bits ( unsigned int data ) 2 { 3 int cnt = 0; 4 5 while( data!= 0 ) { 6 data = data & (data 1); 7 cnt++; 8 } 9 return cnt; 10 } : : on data ( data 0 ) data 0 data 1 6 data data data data 1 data data = xxxxx10000 data - 1 = xxxxx01111 x data data - 1 AND data

64 static unsigned char byte bit count [256]; / / 2 3 void initialize count bits () 4 { 5 int cnt, i, data; 6 7 for ( i = 0; i < 256; i++ ) { 8 cnt = 0; 9 data = i; 10 while( data!= 0 ) { / / 11 data = data & (data 1); 12 cnt++; 13 } 14 byte bit count [ i ] = cnt; 15 } 16 } int count bits ( unsigned int data ) 19 { 20 const unsigned char byte = ( unsigned char ) & data; return byte bit count [ byte [0]] + byte bit count [ byte [1]] + 23 byte bit count [byte [2]] + byte bit count [byte [3]]; 24 } 3.7: ( initialize count bits count bits byte bit count count bits data byte byte[0] data ( little big endian ) (data >> 24) & 0x000000FF

65 int count bits (unsigned int x ) 2 { 3 static unsigned int mask[] = { 0x , 4 0x , 5 0x0F0F0F0F, 6 0x00FF00FF, 7 0x0000FFFF }; 8 int i ; 9 int shift ; / / for( i=0, shift =1; i < 5; i++, shift = 2 ) 12 x = (x & mask[i]) + ( (x >> shift) & mask[i] ); 13 return x; 14 } 3.8: for for for data 1 data = (data & 0x55) + ((data >> 1) & 0x55); 0x data AND ((data >> 1) & 0x55) data data data data & (data >> 1) & or

66 data = (data & 0x33) + ((data >> 2) & 0x33); ( data ): data & (data >> 2) & or data = (data & 0x0F) + ((data >> 4) & 0x0F); (data ): data & (data >> 4) & or data for

67 4 ( C) C C ( ) ( ) 4.1 ([]) 1 mov ax, [Data] ; 2 mov ebx, Data ; ebx = & Data 3 mov ax, [ebx] ; ax = *ebx AX EBX AL AX C EBX EBX EBX 32 (EAX EBX ECX EDX) (ESI, EDI)

68 58 4 C JMP ( C ) 1 ; file: sub1.asm 2 ; 3 %include "asm_io.inc" sub1.asm 4 5 segment.data 6 prompt1 db "Enter a number: ", 0 ; 7 prompt2 db "Enter another number: ", 0 8 outmsg1 db "You entered ", 0 9 outmsg2 db " and ", 0 10 outmsg3 db ", the sum of these is ", segment.bss 13 input1 resd 1 14 input2 resd segment.text 17 global _asm_main 18 _asm_main: 19 enter 0,0 ; 20 pusha mov eax, prompt1 ; 23 call print_string mov ebx, input1 ; input1 ebx 26 mov ecx, ret1 ; ecx 27 jmp short get_int ; 28 ret1: 29 mov eax, prompt2 ; 30 call print_string mov ebx, input2 33 mov ecx, $ + 7 ; ecx = jmp short get_int

69 mov eax, [input1] ; eax = input1 37 add eax, [input2] ; eax += input2 38 mov ebx, eax ; ebx = eax mov eax, outmsg1 41 call print_string ; 42 mov eax, [input1] 43 call print_int ; input1 44 mov eax, outmsg2 45 call print_string ; 46 mov eax, [input2] 47 call print_int ; input2 48 mov eax, outmsg3 49 call print_string ; 50 mov eax, ebx 51 call print_int ; (ebx) 52 call print_nl ; popa 55 mov eax, 0 ; C 56 leave 57 ret 58 ; get_int 59 ; : 60 ; ebx - 61 ; ecx - 62 ; 63 ; eax 64 get_int: 65 call read_int 66 mov [ebx], eax ; 67 jmp ecx ; sub1.asm get int EBX ECX ret $ $ $ $ MOV $ 7

70 CPU (LIFO) PUSH POP ( ) SS ( ) ESP PUSH ESP 4 1 [ESP] POP [ESP] ESP 4. ESP 1000H 1 push dword 1 ; 1 0FFCh ESP = 0FFCh 2 push dword 2 ; 2 0FF8h ESP = 0FF8h 3 push dword 3 ; 3 0FF4h ESP = 0FF4h 4 pop eax ; EAX = 3 ESP = 0FF8h 5 pop ebx ; EBX = 2 ESP = 0FFCh 6 pop ecx ; ECX = 1 ESP = 1000h 80x86 PUSHA EAX EBX ECX EDX ESI EDI EBP ( ) POPA 4.4 CALL RET 80x86 CALL RET RET mov call ebx, input1 get_int 1 32

71 mov call ebx, input2 get_int get int : get_int: call mov ret read_int [ebx], eax 1 get_int: CALL RET get int read int read int RET get int get int RET asm main LIFO 2 call read_int 3 mov [ebx], eax 4 push eax 5 ret ; EAX 4.5 ( ) ( ) CALL RET PC C ( )

72 62 4 ESP + 4 ESP 4.1: ESP + 8 ESP + 4 ESP 4.2: 80x86 ESP( EBP) EAX EBX ECX EDX CALL C CALL ( ) 4.1 ([ESP+4] 2 ) ESP 4.2 ESP + 8 ESP + 4 ESP EBP C EBP EBP ESP ESP EBP EBP ( ) 4.3 2

73 subprogram_label: 2 push ebp ; EBP 3 mov ebp, esp ; EBP = ESP 4 ; subprogram code 5 pop ebp ; EBP 6 ret 4.3: ESP + 8 EBP + 8 ESP + 4 EBP + 4 ESP EBP EBP 4.4: [EBP + 8] C Pascal (RET ) C pascal MS Windows API C stdcall C C C C ( printf scanf ) C Pascal stdcall Pascal ( Pascal ) MS Windows API 4.5 C 3 POP POP ECX POP ADD ADD POP ECX C 54 ( )

74 push dword 1 ; 1 2 call fun 3 add esp, 4 ; 4.5: 1 %include "asm_io.inc" sub3.asm 2 3 segment.data 4 sum dd segment.bss 7 input resd ; 10 ; 11 ; i = 1; 12 ; sum = 0; 13 ; while( get_int(i, &input), input!= 0 ) { 14 ; sum += input; 15 ; i++; 16 ; } 17 ; print_sum(num); 18 segment.text 19 global _asm_main 20 _asm_main: 21 enter 0,0 ; 22 pusha mov edx, 1 ; edx i 25 while_loop: 26 push edx ; i 27 push dword input ; input 28 call get_int 29 add esp, 8 ; i &input mov eax, [input]

75 cmp eax, 0 33 je end_while add [sum], eax ; sum += input inc edx 38 jmp short while_loop end_while: 41 push dword [sum] ; 42 call print_sum 43 pop ecx ; [sum] popa 46 leave 47 ret ; get_int 50 ; ( ) 51 ; ( [ebp + 12] ) 52 ; ( [ebp + 8] ) 53 ; : 54 ; eax ebx 55 segment.data 56 prompt db ") Enter an integer number (0 to quit): ", segment.text 59 get_int: 60 push ebp 61 mov ebp, esp mov eax, [ebp + 12] 64 call print_int mov eax, prompt 67 call print_string call read_int 70 mov ebx, [ebp + 8] 71 mov [ebx], eax ; pop ebp

76 ret ; ; print_sum 77 ; 78 ; : 79 ; ( [ebp+8] ) 80 ; : eax 81 ; 82 segment.data 83 result db "The sum is ", segment.text 86 print_sum: 87 push ebp 88 mov ebp, esp mov eax, result 91 call print_string mov eax, [ebp+8] 94 call print_int 95 call print_nl pop ebp 98 ret sub3.asm ENTER LEAVE C ( C lingo ) (C ) EBP ESP 4.6 EBP 4.7 C C

77 subprogram_label: 2 push ebp ; EBP 3 mov ebp, esp ; EBP = ESP 4 sub esp, LOCAL_BYTES ; = # 5 ; subprogram code 6 mov esp, ebp ; 7 pop ebp ; EBP 8 ret 1 void calc sum( int n, int sump ) 2 { 3 int i, sum = 0; 4 5 for ( i=1; i <= n; i++ ) 6 sum += i; 7 sump = sum; 8 } 4.6: 4.7: C ENTER LEAVE ENTER C 0 LEAVE 4.10 skeleton( 1.7) ENTER LEAVE 4.6 C ( C ) ( ) A B extern( ) extern asm io.inc read int

78 cal_sum: 2 push ebp 3 mov ebp, esp 4 sub esp, 4 ; sum 5 6 mov dword [ebp - 4], 0 ; sum = 0 7 mov ebx, 1 ; ebx (i) = 1 8 for_loop: 9 cmp ebx, [ebp+8] ; is i <= n? 10 jnle end_for add [ebp-4], ebx ; sum += i 13 inc ebx 14 jmp short for_loop end_for: 17 mov ebx, [ebp+12] ; ebx = sump 18 mov eax, [ebp-4] ; eax = sum 19 mov [ebx], eax ; *sump = sum; mov esp, ebp 22 pop ebp 23 ret 4.8:, global( ) global 1.7 skeleton 13 asm main C asm main (get int print sum) asm main 1 %include "asm_io.inc" main4.asm 2 3 segment.data 4 sum dd 0 5

79 ESP + 16 EBP + 12 sump ESP + 12 EBP + 8 n ESP + 8 EBP + 4 Return address ESP + 4 EBP saved EBP ESP EBP - 4 sum 4.9: 1 subprogram_label: 2 enter LOCAL_BYTES, 0 ; = # 3 ; subprogram code 4 leave 5 ret 4.10: ENTER LEAVE 6 segment.bss 7 input resd segment.text 10 global _asm_main 11 extern get_int, print_sum 12 _asm_main: 13 enter 0,0 ; 14 pusha mov edx, 1 ; edx i 17 while_loop: 18 push edx ; i 19 push dword input ; input 20 call get_int 21 add esp, 8 ; i &input mov eax, [input] 24 cmp eax, 0 25 je end_while add [sum], eax ; sum += input inc edx 30 jmp short while_loop

80 end_while: 33 push dword [sum] ; 34 call print_sum 35 pop ecx ; [sum] popa 38 leave 39 ret 1 %include "asm_io.inc" main4.asm sub4.asm 2 3 segment.data 4 prompt db ") Enter an integer number (0 to quit): ", segment.text 7 global get_int, print_sum 8 get_int: 9 enter 0, mov eax, [ebp + 12] 12 call print_int mov eax, prompt 15 call print_string call read_int 18 mov ebx, [ebp + 8] 19 mov [ebx], eax ; leave 22 ret ; segment.data 25 result db "The sum is ", segment.text 28 print_sum: 29 enter 0, mov eax, result 32 call print_string

81 4.7 C mov eax, [ebp+8] 35 call print_int 36 call print_nl leave 39 ret sub4.asm 4.7 C C C NASM Borland Microsoft MASM DJGPP Linux gcc GAS 3 PC C C ( ) C C EBX ESI EDI register EBP CS DS SS ES C 3 GAS GNU AT&T MASM TASM NASM

82 segment.data 2 x dd 0 3 format db "x = %d\n", segment.text push dword [x] ; x 8 push dword format ; format 9 call _printf ;! 10 add esp, 8 ; 4.11: printf EBP + 12 EBP + 8 EBP + 4 EBP x format EBP 4.12: printf EBX ESI EDI C C f f f f Linux gcc Linux ELF C f f DJGPP gcc skeleton ( 1.7) asm main C C printf("x = %d\n",x); 4.11 ( NASM ) 4.12 printf printf C C C format stdarg.h C

83 4.7 C 73 EBP + 8 printf format printf("x = %d\n") printf [EBP + 12] x data bss ( ) ( x) ( foo) x EBP 8 mov eax, ebp - 8 MOV EAX ( ) LEA ( Load Effective Address ) x EAX lea eax, [ebp - 8] EAX x foo [EBP 8] LEA ( dword) C C (char int enum ) EAX 32 EAX 32 ( ) 64 EDX:EAX ST0 ( ) x86 C C

84 C GCC attribute f int void f( int ) attribute (( cdecl )); GCC call cdecl stdcall stdcall cdecl stdcall ( Pascal ) stdcall ( printf scanf) GCC regparm 3 Borland Microsoft C cdecl stdcall f Borland Microsoft void cdecl f( int ); cdecl C C ( ) stdcall cdecl CALL C ( skeleton ( 1.7) driver.c ) main5.c 4 Watcom C Watcom

85 4.7 C 75 1 #include <stdio.h> 2 / / 3 void calc sum( int, int ) attribute (( cdecl )); 4 5 int main( void ) 6 { 7 int n, sum; 8 9 printf ( Sum integers up to: ); 10 scanf( %d, &n); 11 calc sum(n, &sum); 12 printf ( Sum is %d\n, sum); 13 return 0; 14 } 1 ; _calc_sum 2 ; 1 n 3 ; : main5.c sub5.asm 4 ; n - 1 ( [ebp + 8]) 5 ; sump - ( [ebp + 12]) 6 ; C : 7 ; void calc_sum( int n, int * sump ) 8 ; { 9 ; int i, sum = 0; 10 ; for( i=1;i <= n; i++ ) 11 ; sum += i; 12 ; *sump = sum; 13 ; } segment.text 16 global _calc_sum 17 ; 18 ; : 19 ; [ebp-4] sum 20 _calc_sum: 21 enter 4,0 ; sum 22 push ebx ;! mov dword [ebp-4],0 ; sum = 0 25 dump_stack 1, 2, 4 ; ebp-8 ebp+16

86 76 4 Sum integers up to: 10 Stack Dump # 1 EBP = BFFFFB70 ESP = BFFFFB BFFFFB EC +12 BFFFFB7C BFFFFB80 +8 BFFFFB A +4 BFFFFB BFFFFB70 BFFFFB88-4 BFFFFB6C BFFFFB C Sum is : sub5 26 mov ecx, 1 ; ecx i 27 for_loop: 28 cmp ecx, [ebp+8] ; i n 29 jnle end_for ; i > n, add [ebp-4], ecx ; sum += i 32 inc ecx 33 jmp short for_loop end_for: 36 mov ebx, [ebp+12] ; ebx = sump 37 mov eax, [ebp-4] ; eax = sum 38 mov [ebx], eax pop ebx ; ebx 41 leave 42 ret sub5.asm sub5.asm 22 C EBX 25 dump stack EBP EBP 4.13 FBFFFFB80 ( EBP + 12) n A ( EBP + 8) ( EBP + 4) EBP BFFFFB88 ( EBP) 0( EBP - 4) EBX C ( EBP -

87 4.7 C 77 8) calc sum sum sum EAX main5.c 11 sum = calc sum(n); calc sum sub6.asm 1 ; _calc_sum 2 ; 1 n ; : 3 ; n - 1 ( [ebp + 8] 4 ; : 5 ; sum 6 ; C : 7 ; int calc_sum( int n ) 8 ; { 9 ; int i, sum = 0; 10 ; for( i=1; i <= n; i++) 11 ; sum += i; 12 ; return sum; 13 ; } 14 segment.text 15 global _calc_sum 16 ; 17 ; : 18 ; [ebp-4] sum 19 _calc_sum: 20 enter 4,0 ; sum mov dword [ebp-4],0 ; sum = 0 23 mov ecx, 1 ; ecx i 24 for_loop: 25 cmp ecx, [ebp+8] ; i n 26 jnle end_for ; i > n, add [ebp-4], ecx ; sum += i 29 inc ecx 30 jmp short for_loop end_for: 33 mov eax, [ebp-4] ; eax = sum 34

88 segment.data 2 format db "%d", segment.text lea eax, [ebp-16] 7 push eax 8 push dword format 9 call _scanf 10 add esp, : scanf 35 leave 36 ret sub6.asm C C C scanf 4.14 scanf C EBX ESI EDI EAX ECX EDX EAX scanf C asm io.obj asm io.asm 4.8 mov word [cs:$+7], 5 ; 5 add ax, 2 ; 2 5! ( )

89 ( data bss ) DLL(Dynamic Link Libraries ) 5 Windows 9x/NT UNIX (Solaris Linux ) foo foo foo bar bar foo ( ) 4.15 n! C x = fact(3); / find 3! / C 4.18 f(3) ENTER i f i data i C C global ( data bss ) static ( ) 5

90 ; n! 2 segment.text 3 global _fact 4 _fact: 5 enter 0,0 6 7 mov eax, [ebp+8] ; eax = n 8 cmp eax, 1 9 jbe term_cond ; n <= 1 10 dec eax 11 push eax 12 call _fact ; eax = fact(n-1) 13 pop ecx ; eax 14 mul dword [ebp+8] ; edx:eax = eax * [ebp+8] 15 jmp short end_fact 16 term_cond: 17 mov eax, 1 18 end_fact: 19 leave 20 ret 4.15: n!. n=3 n=2 n=1 n(3) EBP n(2) EBP n(1) EBP 4.16: n!

91 void f( int x ) 2 { 3 int i ; 4 for ( i=0; i < x; i++ ) { 5 printf ( %d\n, i); 6 f( i ); 7 } 8 } 4.17: (C ) static ( C static ) ( data bss ) automatic C register ( ) C volatile 1 x = 10; 2 y = 20; 3 z = x; x 1 3 x z 10. x x z 10

92 %define i ebp-4 2 %define x ebp+8 ; useful macros 3 segment.data 4 format db "%d", 10, 0 ; 10 = \n 5 segment.text 6 global _f 7 extern _printf 8 _f: 9 enter 4,0 ; i mov dword [i], 0 ; i = 0 12 lp: 13 mov eax, [i] ; is i < x? 14 cmp eax, [x] 15 jnl quit push eax ; printf 18 push format 19 call _printf 20 add esp, push dword [i] ; f 23 call _f 24 pop eax inc dword [i] ; i++ 27 jmp short lp 28 quit: 29 leave 30 ret 4.18: ( )

93 5 5.1 ( ) 0( C ) data bss data db dw NASM TIMES 5.1 bss resb resw

94 segment.data 2 ; 10 1,2,..,10 3 a1 dd 1, 2, 3,4, 5, 6, 7, 8, 9, 10 4 ; a2 dw 0, 0, 0, 0,0, 0, 0, 0, 0, 0 6 ; TIMES 7 a3 times 10 dw 0 8 ;, a4 times 200 db 0 10 times 100 db segment.bss 13 ; a5 resd ; a6 resw : ESP ( ENTER ) = 109 ESP ESP 4 ( 112 ) C [ ] array1 db 5, 4, 3, 2, 1 ; array2 dw 5, 4, 3, 2, 1 ; 1 mov al, [array1] ; al = array1[0] 2 mov al, [array1 + 1] ; al = array1[1] 3 mov [array1 + 3], al ; array1[3] = al 4 mov ax, [array2] ; ax = array2[0]

95 EBP - 1 char unused EBP - 8 dword 1 EBP - 12 dword 2 word array EBP word array EBP EBP dword 1 EBP dword 2 EBP char unused 5.2: 1 mov ebx, array1 ; ebx = array1 2 mov dx, 0 ; dx 3 mov ah, 0 ;? 4 mov ecx, 5 5 lp: 6 mov al, [ebx] ; al = *ebx 7 add dx, ax ; dx += ax ( al!) 8 inc ebx ; bx++ 9 loop lp 5.3: ( 1) 5 mov ax, [array2 + 2] ; ax = array2[1] ( array2[2]!) 6 mov [array2 + 6], ax ; array2[3] = ax 7 mov ax, [array2 + 1] ; ax =?? 5 1, 2 7 C 5.3 array1 7 AX DX AL ADD DX

96 mov ebx, array1 ; ebx = array1 2 mov dx, 0 ; dx 3 mov ecx, 5 4 lp: 5 add dl, [ebx] ; dl += *ebx 6 jnc next ; next 7 inc dh ; inc dh 8 next: 9 inc ebx ; bx++ 10 loop lp 5.4: ( 2) 1 mov ebx, array1 ; ebx = array1 2 mov dx, 0 ; dx 3 mov ecx, 5 4 lp: 5 add dl, [ebx] ; dl += *ebx 6 adc dh, 0 ; dh += carry flag inc ebx ; bx++ 8 loop lp 5.5: ( 3) 65,535 AH 3 AH [ base reg( ) + factor( ) *index reg( ) + constant( ) ] 1 AH 0 AL 6 7 CBW

97 EAX EBX ECX EDX EBP ESP ESI EDI ( 1 ) EAX EBX ECX EDX EBP ESI EDI ( ESP ) 32 ( ) array1c.c ( ) driver.c 1 %define ARRAY_SIZE %define NEW_LINE 10 array1.asm 3 4 segment.data 5 FirstMsg db "First 10 elements of array", 0 6 Prompt db "Enter index of element to display: ", 0 7 SecondMsg db "Element %d is %d", NEW_LINE, 0 8 ThirdMsg db "Elements 20 through 29 of array", 0 9 InputFormat db "%d", segment.bss 12 array resd ARRAY_SIZE segment.text 15 extern _puts, _printf, _scanf, _dump_line 16 global _asm_main 17 _asm_main: 18 enter 4,0 ; EBP push ebx 20 push esi ; mov ecx, ARRAY_SIZE 25 mov ebx, array 26 init_loop: 27 mov [ebx], ecx 28 add ebx, 4

98 loop init_loop push dword FirstMsg ; FirstMsg 32 call _puts 33 pop ecx push dword push dword array 37 call _print_array ; add esp, ; 41 Prompt_loop: 42 push dword Prompt 43 call _printf 44 pop ecx lea eax, [ebp-4] ; eax = 47 push eax 48 push dword InputFormat 49 call _scanf 50 add esp, 8 51 cmp eax, 1 ; eax = scanf 52 je InputOK call _dump_line ; 55 jmp Prompt_loop ; InputOK: 58 mov esi, [ebp-4] 59 push dword [array + 4*esi] 60 push esi 61 push dword SecondMsg ; 62 call _printf 63 add esp, push dword ThirdMsg ; call _puts 67 pop ecx push dword push dword array + 20*4 ; array[20]

99 call _print_array 72 add esp, pop esi 75 pop ebx 76 mov eax, 0 ; C 77 leave 78 ret ; 81 ; _print_array 82 ; C 83 ; C : 84 ; void print_array( const int * a, int n); 85 ; 86 ; a - ( ebp+8 ) 87 ; n - ( ebp+12 ) segment.data 90 OutputFormat db "%-5d %5d", NEW_LINE, segment.text 93 global _print_array 94 _print_array: 95 enter 0,0 96 push esi 97 push ebx xor esi, esi ; esi = mov ecx, [ebp+12] ; ecx = n 101 mov ebx, [ebp+8] ; ebx = 102 print_loop: 103 push ecx ; printf ecx! push dword [ebx + 4*esi] ; array[esi] 106 push esi 107 push dword OutputFormat 108 call _printf 109 add esp, 12 ; ( ecx!) inc esi 112 pop ecx

100 loop print_loop pop ebx 116 pop esi 117 leave 118 ret array1.asm array1c.c 1 #include <stdio.h> 2 3 int asm main( void ); 4 void dump line( void ); 5 6 int main() 7 { 8 int ret status ; 9 ret status = asm main(); 10 return ret status ; 11 } / * dump line* / 14 void dump line() 15 { 16 int ch; while( (ch = getchar())!= EOF && ch!= \n ) 19 / / ; 20 } array1c.c LEA LEA lea ebx, [4*eax + eax] 5 EAX EBX MUL LEA 6

101 mov eax, [ebp - 44] ; ebp - 44 i 2 sal eax, 1 ; i 2 3 add eax, [ebp - 48] ; j 4 mov eax, [ebp + 4*eax - 40] ; ebp - 40 a[0][0] 5 mov [ebp - 52], eax ; x ( ebp - 52 ) 5.6: x = a[i ][ j ] int a [3][2]; C 6(= 2 3) a[0][0] a[0][1] a[1][0] a[1][1] a[2][0] a[2][1] a[0][0] 6 a[0][1] ( 1) C/C++ a[i][j] i j 2i + j i 2i j j 2i N N i + j gcc ( a) x = a[i ][ j ]; 5.6

102 92 5 ( FORTRANO ) x = (&a[0][0] + 2 i + j); a[0][0] a[1][0] a[2][0] a[0][1] a[1][1] a[2][1] [i][j] i + 3j ( FORTRAN) int b [4][3][2]; [3][2] b[0][0][0] b[0][0][1] b[0][1][0] b[0][1][1] b[0][2][0] b[0][2][1] b[1][0][0] b[1][0][1] b[1][1][0] b[1][1][1] b[1][2][0] b[1][2][1] b[i][j][k] 6i + 2j + k 6 [3][2] a[l][m][n] a[i][j][k] M N i + N j + k (L) D 1 D n n i 1 i n D 2 D 3 D n i 1 + D 3 D 4 D n i D n i n 1 + i n n n i j j=1 k=j+1 D 1 i 1 + D 1 i D 1 D 2 D n 2 i n 1 + D 1 D 2 D n 1 i n n j 1 j=1 k=1 D k D k i j D n

103 5.2 / 93 C C void f( int a[ ][ ] ); / / void f( int a[ ][2] ); 2 void f( int a[ ] ); ( ) void f( int a[ ][4][3][2] ); 5.2 / 80x86 (ESI EDI) 1 1 FLAGS (DF) CLD STD 80x86 ( ) 2

104 94 5 LODSB LODSW LODSD AL = [DS:ESI] ESI = ESI ± 1 AX = [DS:ESI] ESI = ESI ± 2 EAX = [DS:ESI] ESI = ESI ± 4 STOSB STOSW STOSD [ES:EDI] = AL EDI = EDI ± 1 [ES:EDI] = AX EDI = EDI ± 2 [ES:EDI] = EAX EDI = EDI ± 4 1 segment.data 5.7: 2 array1 dd 1, 2, 3, 4, 5, 6, 7, 8, 9, segment.bss 5 array2 resd segment.text 8 cld ; 9 mov esi, array1 10 mov edi, array2 11 mov ecx, lp: 13 lodsd 14 stosd 15 loop lp 5.8: ESI EDI SI Source Index DI Destination Index (AL AX EAX) ES DS ES DS( DS ) ES MOV DS ES MOV DS ( AX) ES

105 5.2 / 95 MOVSB MOVSW MOVSD byte [ES:EDI] = byte [DS:ESI] ESI = ESI ± 1 EDI = EDI ± 1 word [ES:EDI] = word [DS:ESI] ESI = ESI ± 2 EDI = EDI ± 2 dword [ES:EDI] = dword [DS:ESI] ESI = ESI ± 4 EDI = EDI ± 4 5.9: 1 segment.bss 2 array resd segment.text 5 cld ; 6 mov edi, array 7 mov ecx, 10 8 xor eax, eax 9 rep stosd 5.10: LODSx STOSx ( ) MOVSx MOVSD EAX REP 80x86 4 REP CPU ECX ( LOOP ) REP rep movsd

106 96 5 CMPSB CMPSW CMPSD SCASB SCASW SCASD [DS:ESI] [ES:EDI] ESI = ESI ± 1 EDI = EDI ± 1 [DS:ESI] [ES:EDI] ESI = ESI ± 2 EDI = EDI ± 2 [DS:ESI] [ES:EDI] ESI = ESI ± 4 EDI = EDI ± 4 AL [ES:EDI] EDI ± 1 AX [ES:EDI] EDI ± 2 EAX [ES:EDI] EDI ± : CMP FLAGS CMPSx SCASx SCASD EDI 4 12 EDI 4( 16 ) ECX REPx REP 5.13 REPE REPZ (REPNE REPNZ ) ECX 1 FLAGS ZF ECX JE ZF 0, ECX 0 ZF 1, equal

107 5.2 / 97 1 segment.bss 2 array resd segment.text 5 cld 6 mov edi, array ; 7 mov ecx, 100 ; 8 mov eax, 12 ; 9 lp: 10 scasd 11 je found 12 loop lp 13 ; 14 jmp onward 15 found: 16 sub edi, 4 ; edi ; 18 onward: 5.12: REPE, REPZ REPNE, REPNZ ZF 1 ECX ZF 0 ECX 5.13: REPx C memory.asm 1 global _asm_copy, _asm_find, _asm_strlen, _asm_strcpy 2 3 segment.text 4 ; _asm_copy 5 ; 6 ; C 7 ; void asm_copy( void * dest, const void * src, unsigned sz); 8 ; : 9 ; dest - 10 ; src -

108 segment.text 2 cld 3 mov esi, block1 ; block1 4 mov edi, block2 ; block2 5 mov ecx, size ; block 6 repe cmpsb ; ZF 1 7 je equal ; ZF 1, equal 8 ; block 9 jmp onward 10 equal: 11 ; 12 onward: 5.14: 11 ; sz ; %define dest [ebp+8] 16 %define src [ebp+12] 17 %define sz [ebp+16] 18 _asm_copy: 19 enter 0, 0 20 push esi 21 push edi mov esi, src ; esi = 24 mov edi, dest ; edi = 25 mov ecx, sz ; ecx = cld ; 28 rep movsb ; movsb ECX pop edi 31 pop esi 32 leave 33 ret ; _asm_find

109 5.2 / ; 38 ; void * asm_find( const void * src, char target, unsigned sz); 39 ; : 40 ; src - 41 ; target - 42 ; sz - 43 ; : 44 ; target target 45 ; 46 ; NULL 47 ; : target 48 ; 8 49 ; 50 %define src [ebp+8] 51 %define target [ebp+12] 52 %define sz [ebp+16] _asm_find: 55 enter 0,0 56 push edi mov eax, target ; al 59 mov edi, src 60 mov ecx, sz 61 cld repne scasb ; ECX == 0 [ES:EDI] == AL je found_it ; ZF 1, 66 mov eax, 0 ; NULL 67 jmp short quit 68 found_it: 69 mov eax, edi 70 dec eax ; (DI - 1) 71 quit: 72 pop edi 73 leave 74 ret ; _asm_strlen 78 ;

110 ; unsigned asm_strlen( const char * ); 80 ; : 81 ; src - 82 ; : 83 ; ( 0 0, ) ( EAX ) %define src [ebp + 8] 86 _asm_strlen: 87 enter 0,0 88 push edi mov edi, src ; edi = 91 mov ecx, 0FFFFFFFFh ; ECX 92 xor al,al ; al = 0 93 cld repnz scasb ; ; 98 ; repnz ECX FFFFFFFE 99 ; FFFFFFFF 100 ; 101 mov eax,0fffffffeh 102 sub eax, ecx ; = 0FFFFFFFEh - ecx pop edi 105 leave 106 ret ; _asm_strcpy 109 ; 110 ; void asm_strcpy( char * dest, const char * src); 111 ; : 112 ; dest ; src ; 115 %define dest [ebp + 8] 116 %define src [ebp + 12] 117 _asm_strcpy: 118 enter 0,0 119 push esi 120 push edi

111 5.2 / mov edi, dest 123 mov esi, src 124 cld 125 cpy_loop: 126 lodsb ; AL & inc si 127 stosb ; AL & inc di 128 or al, al ; 129 jnz cpy_loop ; 0, pop edi 132 pop esi 133 leave 134 ret memory.asm memex.c 1 #include <stdio.h> 2 3 #define STR SIZE 30 4 / / 5 6 void asm copy( void, const void, unsigned ) attribute (( cdecl )); 7 void asm find( const void, 8 char target, unsigned ) attribute (( cdecl )); 9 unsigned asm strlen ( const char ) attribute (( cdecl )); 10 void asm strcpy( char, const char ) attribute (( cdecl )); int main() 13 { 14 char st1 [STR SIZE] = test string ; 15 char st2 [STR SIZE]; 16 char st ; 17 char ch; asm copy(st2, st1, STR SIZE); / 30 / 20 printf ( %s\n, st2); printf ( Enter a char: ); / / 23 scanf( %c% [ˆ\n], &ch); 24 st = asm find(st2, ch, STR SIZE);

,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20

,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20 (Jump) (Loop) (Conditional jump) CMP CALL AND SAR/SHR TEST JMP NOT SAL/SHL Jnnn* OR RCR/ROR LOOP XOR RCL/ROL RETn * nnn, JNE JL -128 127-32,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far

More information

untitled

untitled 8086/8088 CIP /. 2004.8 ISBN 7-03-014239-X.... TP313 CIP 2004 086019 16 100717 http://www.sciencep.com * 2004 8 2004 8 1 5 500 787 1092 1/16 16 1/2 391 000 1 2 ii 1 2 CAI CAI 3 To the teacher To the student

More information

Microsoft PowerPoint - C15_LECTURE_NOTE_06

Microsoft PowerPoint - C15_LECTURE_NOTE_06 8088/8086 MICROPROCESSOR PROGRAMMING CONTROL FLOW INSTRUCTIONS AND PROGRAM STRUCTURES 8088/8086 MICROPROCESSOR PROGRAMMING CONTROL FLOW INSTRUCTIONS AND PROGRAM STRUCTURES 61 Flag-Control 62 Compare 63

More information

Microsoft PowerPoint - C15_LECTURE_NOTE_06

Microsoft PowerPoint - C15_LECTURE_NOTE_06 61 Flag-Control 8088/8086 MICROPROCESSOR PROGRAMMING CONTROL FLOW INSTRUCTIONS AND PROGRAM STRUCTURES LAHF SAHF CLC STC CMC CLI STI Load AH from flags Store AH into flags Clear carry flag Set carry flag

More information

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt 8088/8086 MICROPROCESSOR PROGRAMMING INTEGER INSTRUCTIONS AND COMPUTATIONS 8088/8086 MICROPROCESSOR PROGRAMMING INTEGER INSTRUCTIONS AND COMPUTATIONS 5.1 Data-Transfer Instructions 5.2 Arithmetic Instructions

More information

42 2141601026 2016 11 27 2 1.1............................................. 2 1.2....................................... 2 1.2.1......................................... 2 1.3.............................................

More information

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt 8088/8086 MICROPROCSOR PROGRAMMING INTEGER INSTRUCTIONS AND COMPUTATIONS The MOVE The move (MOV) instruction is used to transfer a byte or a word of data from a source operand to a destination operand

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

幻灯片 1

幻灯片 1 3 8086 Tel:2656809 tjx@csu.edu.cn 2005-9-14 1 2005-9-14 2 8086 8 8086 8086 7 2005-9-14 3 PC 2005-9-14 4 2005-9-14 5 81616 2005-9-14 6 [ ] MOV AX, 3064H AX=3064H 16AX OP 64H 30H 2005-9-14 7 16 AX BX CX

More information

<4D6963726F736F667420576F7264202D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63>

<4D6963726F736F667420576F7264202D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63> 因 为 路 过 你 的 路, 因 为 苦 过 你 的 苦, 所 以 快 乐 着 你 的 快 乐, 追 逐 着 你 的 追 逐 内 容 简 介 本 书 根 据 2005 年 下 半 年 实 施 的 全 国 计 算 机 技 术 与 软 件 专 业 技 术 资 格 ( 水 平 ) 考 试 嵌 入 式 系 统 设 计 师 级 考 试 大 纲 精 神, 在 深 入 研 究 历 年 计 算 机 技 术 与 软

More information

学习MSP430单片机推荐参考书

学习MSP430单片机推荐参考书 MSP430 16 MSP430 C MSP430 C MSP430 FLASH 16 1 CPU 16 ALU 16 PC SP SR R4~R15 2 3 00-FFH 100-1FFH 4 5 1 2 51 24 27 6 1 2 3 4 5 6 4 12 SR SP SR CPU SR CPU C Z N GIE CPUOff CPU OscOff SCG0 SCG1 CPU EXIT SP

More information

C/C++ - 字符输入输出和字符确认

C/C++ - 字符输入输出和字符确认 C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,

More information

新版 明解C言語入門編

新版 明解C言語入門編 328, 4, 110, 189, 103, 11... 318. 274 6 ; 10 ; 5? 48 & & 228! 61!= 42 ^= 66 _ 82 /= 66 /* 3 / 19 ~ 164 OR 53 OR 164 = 66 ( ) 115 ( ) 31 ^ OR 164 [] 89, 241 [] 324 + + 4, 19, 241 + + 22 ++ 67 ++ 73 += 66

More information

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File 51 C 51 51 C C C C C C * 2003-3-30 pnzwzw@163.com C C C C KEIL uvision2 MCS51 PLM C VC++ 51 KEIL51 KEIL51 KEIL51 KEIL 2K DEMO C KEIL KEIL51 P 1 1 1 1-1 - 1 Project New Project 1 2 Windows 1 3 N C test

More information

untitled

untitled MODBUS 1 MODBUS...1 1...4 1.1...4 1.2...4 1.3...4 1.4... 2...5 2.1...5 2.2...5 3...6 3.1 OPENSERIAL...6 3.2 CLOSESERIAL...8 3.3 RDMULTIBIT...8 3.4 RDMULTIWORD...9 3.5 WRTONEBIT...11 3.6 WRTONEWORD...12

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

1

1 1 2 3 4 5 GNUDebugger 6 7 void main(int argc, char **argv){ vulncpy(argv[1]); return; } void vulncpy(char *a){ char buf[30]; strcpy(buf, a); return; } *argv[1] buf Shellcode *argv[1]... &buf &buf 8 strcpy

More information

(2) Function 0BH: Function 0CH: (pixel, picture element) Function 0DH: Function 0FH: Function 13H:

(2) Function 0BH: Function 0CH: (pixel, picture element) Function 0DH: Function 0FH: Function 13H: (1) INT 10H Function 00H: Function 01H: Function 02H: Function 03H: Function 05H: Function 06H: Function 07H: Function 08H: Function 09H: Function 0AH: (2) Function 0BH: Function 0CH: (pixel, picture element)

More information

Linux kernel exploit研究和探索

Linux kernel exploit研究和探索 Linux kernel exploit DOC alert7 PPT e4gle 2002-12-2 1 2002-12-2 2 Linux kernel exploit kernel exploit exploit exploit exploit (Kernel Buffer Overflow) (Kernel

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

新・解きながら学ぶC言語

新・解きながら学ぶC言語 330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180

More information

C/C++语言 - 运算符、表达式和语句

C/C++语言 - 运算符、表达式和语句 C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe

More information

51 C 51 isp 10 C PCB C C C C KEIL

51 C 51 isp 10   C   PCB C C C C KEIL http://wwwispdowncom 51 C " + + " 51 AT89S51 In-System-Programming ISP 10 io 244 CPLD ATMEL PIC CPLD/FPGA ARM9 ISP http://wwwispdowncom/showoneproductasp?productid=15 51 C C C C C ispdown http://wwwispdowncom

More information

Microsoft PowerPoint - os_4.ppt

Microsoft PowerPoint - os_4.ppt 行 程 資 科 系 林 偉 川 行 程 概 念 行 程 與 程 式 主 要 的 不 同 點 : 程 式 是 被 放 在 外 部 的 儲 存 裝 置 如 磁 碟 上, 而 行 程 則 被 放 在 記 憶 體 中 程 式 在 儲 存 裝 置 中 是 靜 態 的, 而 行 程 在 記 憶 體 中 是 動 態 的, 它 會 隨 著 一 些 事 件 的 發 生 而 產 生 相 對 的 改 變 行 程, 就 是

More information

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023) ( CIP) /. :, 2005. 2 ( ) ISBN 7-5624-3339-9.......... TP311. 1 CIP ( 2005) 011794 : : : : * : : 174 ( A ) :400030 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / /www. cqup. com. cn : fxk@cqup.

More information

C/C++ - 字符串与字符串函数

C/C++ - 字符串与字符串函数 C/C++ Table of contents 1. 2. 3. 4. 1 char C 2 char greeting [50] = " How " " are " " you?"; char greeting [50] = " How are you?"; 3 printf ("\" Ready, go!\" exclaimed John."); " Ready, go!" exclaimed

More information

新・明解C言語入門編『索引』

新・明解C言語入門編『索引』 !... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177

More information

C C

C C C C 2017 3 8 1. 2. 3. 4. char 5. 2/101 C 1. 3/101 C C = 5 (F 32). 9 F C 4/101 C 1 // fal2cel.c: Convert Fah temperature to Cel temperature 2 #include 3 int main(void) 4 { 5 float fah, cel; 6 printf("please

More information

nooog

nooog C : : : , C C,,, C, C,, C ( ), ( ) C,,, ;,, ; C,,, ;, ;, ;, ;,,,, ;,,, ; : 1 9, 2 3, 4, 5, 6 10 11, 7 8, 12 13,,,,, 2008 1 1 (1 ) 1.1 (1 ) 1.1.1 ( ) 1.1.2 ( ) 1.1.3 ( ) 1.1.4 ( ) 1.1.5 ( ) 1.2 ( ) 1.2.1

More information

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt MACHINE LANGUAGE CODING AND THE DEBUG SOFTWARE DEVELOPMENT PROGRAM OF THE PC General instruction format for machine code 611 37100 微處理機原理與應用 Lecture 04-4 MACHINE LANGUAGE CODING AND THE DEBUG SOFTWARE

More information

untitled

untitled 不 料 料 例 : ( 料 ) 串 度 8 年 數 串 度 4 串 度 數 數 9- ( ) 利 數 struct { ; ; 數 struct 數 ; 9-2 數 利 數 C struct 數 ; C++ 數 ; struct 省略 9-3 例 ( 料 例 ) struct people{ char name[]; int age; char address[4]; char phone[]; int

More information

Ps22Pdf

Ps22Pdf C ( CIP) C /. :, 2001. 7 21 ISBN 7-5624 -2355-5. C........ C. TP312 CIP ( 2001 ) 034496 C * * : 7871092 1 /16 : 14. 25 : 356 20017 1 20017 1 : 1 6 000 ISBN 7-5624-2355-5 / TP311 : 21. 00 C, C,,,, C,, (

More information

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt MACHINE LANGUAGE CODING AND THE DEBUG SOFTWARE DEVELOPMENT PROGRAM OF THE PC MACHINE LANGUAGE CODING AND THE DEBUG SOFTWARE DEVELOPMENT PROGRAM OF THE PC 4.1 Converting Assembly Language Instructions to

More information

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc 2 5 8 11 0 13 1. 13 2. 15 3. 18 1 23 1. 23 2. 26 3. 28 2 36 1. 36 2. 39 3. 42 4. 44 5. 49 6. 51 3 57 1. 57 2. 60 3. 64 4. 66 5. 70 6. 75 7. 83 8. 85 9. 88 10. 98 11. 103 12. 108 13. 112 4 115 1. 115 2.

More information

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 WWW PHP 2003 1 Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 Comments PHP Shell Style: # C++ Style: // C Style: /* */ $value = $p * exp($r * $t); # $value

More information

/ / (FC 3)...

/ / (FC 3)... Modbus/TCP 1.0 1999 3 29 Andy Swales Schneider aswales@modicon.com ... 2 1.... 3 2.... 3 2.1.. 3 2.2..4 2.3..4 2.4... 5 3.... 5 3.1 0... 5 3.2 1... 5 3.3 2... 6 3.4 / /... 7 4.... 7 5.... 8 5.1 0... 9

More information

_汪_文前新ok[3.1].doc

_汪_文前新ok[3.1].doc 普 通 高 校 本 科 计 算 机 专 业 特 色 教 材 精 选 四 川 大 学 计 算 机 学 院 国 家 示 范 性 软 件 学 院 精 品 课 程 基 金 青 年 基 金 资 助 项 目 C 语 言 程 序 设 计 (C99 版 ) 陈 良 银 游 洪 跃 李 旭 伟 主 编 李 志 蜀 唐 宁 九 李 涛 主 审 清 华 大 学 出 版 社 北 京 i 内 容 简 介 本 教 材 面 向

More information

06721 main() lock pick proc() restart() [2][4] MINIX minix2.0 GDT, IDT irq table[] CPU CPU CPU CPU (IDTR) idt[] CPU _hwint00:! Interrupt

06721 main() lock pick proc() restart() [2][4] MINIX minix2.0 GDT, IDT irq table[] CPU CPU CPU CPU (IDTR) idt[] CPU _hwint00:! Interrupt MINIX ( 730000) ( 730000) MINIX MINIX2.0 MINIX : MINIX TP3 1 MINIX UNIX Tanenbaum UNIX MINIX LINUX MINIX MINIX MINIX1.0 UNIX V7 MINIX2.0[3] POSIX MINIX3 MINIX Gabriel A. Wainer 1994-1995 [5] 1998 I/O 2002

More information

DPJJX1.DOC

DPJJX1.DOC 8051 111 2K 1 2 3 ' ' 1 CPU RAM ROM / A/D D/A PC CPU 40 68 10 20 8 51 PIII 8051 2 MCS51 8051 8031 89C51 8051 8031 89C51? MCS51 INTEL INTEL 8031 8051 8751 8032 8052 8752 8051 8051 8051 MCS51 8031 8031

More information

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1 21 , 7, Windows,,,, : 010-62782989 13501256678 13801310933,,,, ;,, ( CIP) /,,. : ;, 2005. 11 ( 21 ) ISBN 7-81082 - 634-4... - : -. TP316-44 CIP ( 2005) 123583 : : : : 100084 : 010-62776969 : 100044 : 010-51686414

More information

ROP_bamboofox.key

ROP_bamboofox.key ROP Return Oriented Programming Lays @ BambooFox Who Am I Lays / L4ys / 累死 - l4ys.tw Reverse Engineering BambooFox / HITCON Outline Buffer Overflow ret2libc / ret2text Return Oriented Programming Payload

More information

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit 6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C51 6.1 C51 6.1.1 C51 C51 ANSI C MCS-51 C51 ANSI C C51 6.1 6.1 C51 bit Byte bit sbit 1 0 1 unsigned char 8 1 0 255 Signed char 8 11 128

More information

目 录

目 录 1 Quick51...1 1.1 SmartSOPC Quick51...1 1.2 Quick51...1 1.3 Quick51...2 2 Keil C51 Quick51...4 2.1 Keil C51...4 2.2 Keil C51...4 2.3 1 Keil C51...4 2.4 Flash Magic...9 2.5 ISP...9 2.6...10 2.7 Keil C51...12

More information

C 1

C 1 C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 9 [P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10 C / C++ C C++ C C++ C++ C ( ) C++

More information

Computer Architecture

Computer Architecture ECE 3120 Computer Systems Assembly Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120 Prev: Basic computer concepts

More information

3.1 num = 3 ch = 'C' 2

3.1 num = 3 ch = 'C' 2 Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:

More information

プログラムの設計と実現II

プログラムの設計と実現II UNIX C ls mkdir man http://www.tj.chiba-u.jp/lecture/prog2/ Ctrl+x, Ctrl+s ( )..[4]% gcc Wall o hoge hoge.c..[5]%./hoge 1 : 1 2 : 2 3 : 3 4 : 0 6..[6]% (! )..[4]% gcc Wall o hoge hoge.c..[5]%!g gcc Wall

More information

科学计算的语言-FORTRAN95

科学计算的语言-FORTRAN95 科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造

More information

Microsoft Word - 選擇_無解答2_.doc

Microsoft Word - 選擇_無解答2_.doc 選 擇 題 : 1 ( ) 下 列 何 者 為 W W W 的 通 訊 協 定? (A)H T T P ( H y p e r T e x t T r a n s f e r P r o t o c o l ) (B)S M T P ( S i m p l e M a i l T r a n s f e r P r o t o c o l ) (C) F T P ( F i l e T r a n

More information

untitled

untitled MPICH anzhulin@sohu.com 1 MPICH for Microsoft Windows 1.1 MPICH for Microsoft Windows Windows NT4/2000/XP Professional Server Windows 95/98 TCP/IP MPICH MS VC++ 6.x MS VC++.NET Compaq Visual Fortran 6.x

More information

<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>

<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344> 1. 請 問 誰 提 出 積 體 電 路 (IC) 上 可 容 納 的 電 晶 體 數 目, 約 每 隔 24 個 月 (1975 年 更 改 為 18 個 月 ) 便 會 增 加 一 倍, 效 能 也 將 提 升 一 倍, 也 揭 示 了 資 訊 科 技 進 步 的 速 度? (A) 英 特 爾 (Intel) 公 司 創 始 人 戈 登. 摩 爾 (Gordon Moore) (B) 微 軟 (Microsoft)

More information

第 15 章 程 式 編 写 語 言 15.1 程 式 編 写 語 言 的 角 色 程 式 編 寫 語 言 是 程 式 編 寫 員 與 電 腦 溝 通 的 界 面 語 法 是 一 組 規 則 讓 程 式 編 寫 員 將 字 詞 集 合 起 來 電 腦 是 處 理 位 元 和 字 節 的 機 器, 與

第 15 章 程 式 編 写 語 言 15.1 程 式 編 写 語 言 的 角 色 程 式 編 寫 語 言 是 程 式 編 寫 員 與 電 腦 溝 通 的 界 面 語 法 是 一 組 規 則 讓 程 式 編 寫 員 將 字 詞 集 合 起 來 電 腦 是 處 理 位 元 和 字 節 的 機 器, 與 程 式 編 写 語 言 在 完 成 這 章 後, 你 將 能 夠 了 解 程 式 編 写 語 言 的 功 能 了 解 高 階 語 言 和 低 階 語 言 之 間 的 分 別 知 道 翻 譯 程 式 的 意 義 和 能 夠 把 翻 譯 程 式 分 類 為 : 匯 編 程 式 編 譯 程 式 和 解 譯 程 式 認 識 不 同 翻 譯 程 式 的 優 點 和 缺 點 程 式 是 指 揮 電 腦 的 指

More information

C/C++ - 数组与指针

C/C++ - 数组与指针 C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 float candy [ 365]; char code [12]; int states [50]; 2 int array [6] = {1, 2, 4, 6, 8, 10}; 3 // day_mon1.c: # include # define MONTHS 12 int

More information

untitled

untitled 3 C++ 3.1 3.2 3.3 3.4 new delete 3.5 this 3.6 3.7 3.1 3.1 class struct union struct union C class C++ C++ 3.1 3.1 #include struct STRING { typedef char *CHARPTR; // CHARPTR s; // int strlen(

More information

c_cpp

c_cpp C C++ C C++ C++ (object oriented) C C++.cpp C C++ C C++ : for (int i=0;i

More information

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor 1 4.1.1.1 (Load) 14 1.1 1 4.1.1.2 (Save) 14 1.1.1 1 4.1.2 (Buffer) 16 1.1.2 1 4.1.3 (Device) 16 1.1.3 1 4.1.3.1 (Select Device) 16 2 4.1.3.2 (Device Info) 16 2.1 2 4.1.3.3 (Adapter) 17 2.1.1 CD-ROM 2 4.1.4

More information

目录

目录 ALTERA_CPLD... 3 11SY_03091... 3 12SY_03091...4....5 21 5 22...8 23..10 24..12 25..13..17 3 1EPM7128SLC.......17 3 2EPM7032SLC.......18 33HT46R47......19..20 41..20 42. 43..26..27 5151DEMO I/O...27 52A/D89C51...28

More information

1. ( B ) IT (A) (B) (C) (D) 2. ( A ) (A) (B) (C) (D) 3. ( B ) (A) GPS (B) GIS (C) ETC (D) CAI 4. ( D ) (A) (B) (C) (D) 5. ( B ) (Stored Program) (A) H

1. ( B ) IT (A) (B) (C) (D) 2. ( A ) (A) (B) (C) (D) 3. ( B ) (A) GPS (B) GIS (C) ETC (D) CAI 4. ( D ) (A) (B) (C) (D) 5. ( B ) (Stored Program) (A) H ... 2... 4... 6... 8... 10... 12... 14... 16... 18... 20... 22... 24... 25... 26... 28 1. ( B ) IT (A) (B) (C) (D) 2. ( A ) (A) (B) (C) (D) 3. ( B ) (A) GPS (B) GIS (C) ETC (D) CAI 4. ( D ) (A) (B) (C)

More information

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40 C C trio@seu.edu.cn C C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C 40 30 10 Project 30 C Project 3 60 Project 40 Week3 C Week5 Week5 Memory & Pointer

More information

Microsoft PowerPoint - STU_EC_Ch02.ppt

Microsoft PowerPoint - STU_EC_Ch02.ppt 樹德科技大學資訊工程系 Chapter 2: Number Systems Operations and Codes Shi-Huang Chen Sept. 2010 1 Chapter Outline 2.1 Decimal Numbers 2.2 Binary Numbers 2.3 Decimal-to-Binary Conversion 2.4 Binary Arithmetic 2.5

More information

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; Memory & Pointer trio@seu.edu.cn 2.1 2.1.1 1 int *p int a 0x00C7 0x00C7 0x00C7 2.1.2 2 int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; 2.1.3 1. 2. 3. 3 int A,

More information

1 CPU interrupt INT trap CPU exception

1 CPU interrupt INT trap CPU exception 1 CPU interrupt INT trap CPU exception 2 X86 CPU gate 64 16 1 2 5 8 16 16 P DPL 00101 TSS 101 DPL P 1 64 16 1 2 1 1 3 3 5 16 16 16 P DPL 0 D 000 16 110 111 100 D 1=32 0=16 DPL P 1 INT DPL1>=CPL>=DPL CPU

More information

1 CPU

1 CPU 2000 Tel 82316285 82317634 Mail liuxd@buaa.edu.cn 1 CPU 2 CPU 7 72 A B 85 15 3 1/2 M301 2~17 : 3/4 1/2 323 IBM PC 1. 2. 3. 1. 2. 3. 1.1 Hardware Software 1.2 M3 M2 M1 1.2 M3 M1 M2 M2 M1 M1 M1 1.2 M3 M1

More information

Simulator By SunLingxi 2003

Simulator By SunLingxi 2003 Simulator By SunLingxi sunlingxi@sina.com 2003 windows 2000 Tornado ping ping 1. Tornado Full Simulator...3 2....3 3. ping...6 4. Tornado Simulator BSP...6 5. VxWorks simpc...7 6. simulator...7 7. simulator

More information

1-1 SH79F6431 A. 2( ) 9~15V ( 12V) U2 U3 3.3V SH79F B. 1(VCC/GND) SH79F6431 C. VDDIO SH79F6431 P4 P5 P0.6 P0.7 VDDIO VDDIO=5V D. 2 V 1.0

1-1 SH79F6431 A. 2( ) 9~15V ( 12V) U2 U3 3.3V SH79F B. 1(VCC/GND) SH79F6431 C. VDDIO SH79F6431 P4 P5 P0.6 P0.7 VDDIO VDDIO=5V D. 2 V 1.0 SH79F6431 1. SH79F6431 1T 8051 FLASH SH79F JET51 Keil µ vision JTAG 1.1. SH79F6431 LQFP64 1.2. (Target Board) SH79F6431 1 V 1.0 1-1 SH79F6431 A. 2( ) 9~15V ( 12V) U2 U3 3.3V SH79F6431 1 2 1 B. 1(VCC/GND)

More information

目 录 1 正 文 乊 前... 5 1.1 目 癿... 5 1.2 本 文 内 容... 5 1.3 声 明... 5 2 字 符 编 码 相 兰 癿 背 景 知 识... 6 2.1 拉 丁 字 母... 6 2.2 什 么 是 字 符 编 码... 6 3 字 符 编 码 标 准... 8

目 录 1 正 文 乊 前... 5 1.1 目 癿... 5 1.2 本 文 内 容... 5 1.3 声 明... 5 2 字 符 编 码 相 兰 癿 背 景 知 识... 6 2.1 拉 丁 字 母... 6 2.2 什 么 是 字 符 编 码... 6 3 字 符 编 码 标 准... 8 关 键 字 字 符 编 码 详 解 版 本 : 1.0 作 者 : crifan 邮 箱 : green-waste (at)163.com 字 符 编 码,ASCII,ISO 8859,ISO 10646,UCS,Unicode,UTF-8 版 本 版 本 日 期 内 容 更 新 1.0 2011-11-02 添 加 了 编 码 相 兰 背 景 知 识 仃 绉 添 加 了 ASCII 和 EASCII

More information

新版 明解C++入門編

新版 明解C++入門編 511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,

More information

Microsoft Word - 正文.doc

Microsoft Word - 正文.doc 1 2 1 2 3 4 5 6 7 8 9 10 3 1 150 2 150 1 1 1.1 1.1.1 1.2 1.2.1 1.2.2 1.2.3 1.3 1.3.1 1.3.2 1.4 1.4.1 CPU 1.4.2 I/O 1.4.3 I/O 1.5 1.5.1 CISC RISC 1.5.2 1.5.3 1.6 1.6.1 1.6.2 N 1.6.3 2 2.1 2.1.1 2.1.2 2.1.3

More information

Microsoft Word - 最新正文.doc

Microsoft Word - 最新正文.doc 9 21 1.1.1 1.1.2 1 2 2 Windows 7+Office 2010 3 4 5 6 4 7 1.1.3 5 1.1.4 1 3 2 NII 1993 3 CNNIC 2014 1 16 33 1 2013 12 6.18 5358 45.8% 2012 3.7 2 2013 12 5 19.1% 2012 74.5% 81.0% 2013 3G 2013 12 2.47 2012

More information

untitled

untitled A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (

More information

C/C++ - 结构体、共用体、枚举体

C/C++ - 结构体、共用体、枚举体 C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 C C (struct) C 2 C C (struct) C 2 i // book.c: # include < stdio.h> # define MAX_ TITLE 41 # define MAX_ AUTHOR 31 struct book { char title [ MAX_ TITLE

More information

漏 洞 攻 防 EXPLOIT ATTACK & DEFENCE 栏 目 编 辑 脚 本 小 子 scriptsboy@hacker.com.cn HEAD 部 分 大 小 当 然 也 就 是 固 定 的 18200H 如 果 要 提 取 出 HEAD, 我 们 可 以 选 中 前 18200H 字

漏 洞 攻 防 EXPLOIT ATTACK & DEFENCE 栏 目 编 辑 脚 本 小 子 scriptsboy@hacker.com.cn HEAD 部 分 大 小 当 然 也 就 是 固 定 的 18200H 如 果 要 提 取 出 HEAD, 我 们 可 以 选 中 前 18200H 字 适 合 读 者 : 入 侵 爱 好 者 溢 出 爱 好 者 前 置 知 识 : 汇 编 语 言 缓 冲 区 溢 出 基 本 原 理 文 / 图 何 永 强 Word 畸 形 数 据 结 构 溢 出 漏 洞 分 析 与 利 用 以 前 都 是 写 远 程 溢 出 漏 洞, 感 觉 也 该 换 换 口 味 了 事 实 上,2005 年 以 来 的 远 程 溢 出 漏 洞, 如 MS05-039 MS06-040

More information

本文由筱驀釹贡献

本文由筱驀釹贡献 本 文 由 筱 驀 釹 贡 献 ppt 文 档 可 能 在 WAP 端 浏 览 体 验 不 佳 建 议 您 优 先 选 择 TXT, 或 下 载 源 文 件 到 本 机 查 看 Linux 操 作 系 统 Linux 操 作 系 统 第 一 部 分 介 绍 与 安 装 Linux 的 由 来 : Linux 的 由 来 : 的 由 来 Linus Torvalds 1.Linux 的 版 本 1.Linux

More information

TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP

TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP TCP/IP : TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP 1. ASCII EBCDIC Extended Binary-Coded Decimal Interchange Code 2. / (1) (2) Single System Image SSI) (3) I/O (4) 3.OSI OSI Open System Interconnection

More information

6020

6020 6020 ... 1 1.1... 1 1.2... 1 1.3 6020... 2 1.3... 5 1.3.1... 5 1.3.2 ISA I/O (S1)... 5 1.3.3 (J4,5,6)... 6 1.3.4... 6... 9 2.1... 9 2.2... 9 2.3 COMPILING AND LINKING... 11 2.3.1 MICROSOFT C MICROSOFT

More information

C

C C 2017 4 1 1. 2. while 3. 4. 5. for 6. 2/161 C 7. 8. (do while) 9. 10. (nested loop) 11. 12. 3/161 C 1. I 1 // summing.c: 2 #include 3 int main(void) 4 { 5 long num; 6 long sum = 0L; 7 int status;

More information

untitled

untitled 1 5 IBM Intel 1. IBM 第 1/175 页 第 2/175 页 第 3/175 页 80 第 4/175 页 2. IBM 第 5/175 页 3. (1) 第 6/175 页 第 7/175 页 第 8/175 页 = = 第 9/175 页 = = = = = 第 10/175 页 = = = = = = = = 3. (2) 第 11/175 页 第 12/175 页 第 13/175

More information

PowerPoint 演示文稿

PowerPoint 演示文稿 Linux 操 作 系 统 基 础 介 绍 课 程 目 标 及 要 求 了 解 Linux 操 作 系 统 的 登 入 方 式 掌 握 常 用 命 令 的 基 本 用 法 能 够 熟 练 在 各 个 目 录 转 换 Outline 1. Linux 操 作 系 统 简 介 2. Linux 操 作 系 统 的 登 录 3. Linux 操 作 系 统 的 目 录 结 构 4. 常 用 命 令 5.

More information

Microsoft Word - 97.01.30軟體設計第二部份範例試題_C++_ _1_.doc

Microsoft Word - 97.01.30軟體設計第二部份範例試題_C++_ _1_.doc 電 腦 軟 體 設 計 乙 級 技 術 士 技 能 檢 定 術 科 測 試 範 例 試 題 (C++) 試 題 編 號 :11900-920201-4 審 定 日 期 : 94 年 7 月 1 日 修 訂 日 期 : 96 年 2 月 1 日 97 年 1 月 30 日 ( 第 二 部 份 ) 電 腦 軟 體 設 計 乙 級 技 術 士 技 能 檢 定 術 科 測 試 應 檢 參 考 資 料 壹 試

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

微型计算机原理及应用试题 机电96

微型计算机原理及应用试题   机电96 微 机 原 理 试 题 ( 一 ) 总 分 : 一 : 单 项 选 择 题 ( 每 题 1 分, 共 10 分 ) 1. 微 型 计 算 机 中 主 要 包 括 有 ( ) A) 微 处 理 器 存 储 器 和 I/O 接 口 B) 微 处 理 器 运 算 器 和 存 储 器 C) 控 制 器 运 算 器 和 寄 存 器 组 D) 微 处 理 器 运 算 器 和 寄 存 器 2. DMA 控 制 器

More information

IP505SM_manual_cn.doc

IP505SM_manual_cn.doc IP505SM 1 Introduction 1...4...4...4...5 LAN...5...5...6...6...7 LED...7...7 2...9...9...9 3...11...11...12...12...12...14...18 LAN...19 DHCP...20...21 4 PC...22...22 Windows...22 TCP/IP -...22 TCP/IP

More information

Microsoft Word - NHIS2013_C_130716_送印_.doc

Microsoft Word - NHIS2013_C_130716_送印_.doc 核 准 機 關 : 行 政 院 主 計 總 處 核 准 文 號 : 主 普 管 字 第 1020400481 號 有 效 期 間 : 至 103 年 6 月 30 日 止 辦 理 機 關 : 財 團 法 人 國 家 衛 生 研 究 院 行 政 院 衛 生 署 國 民 健 康 局 IRB 通 過 案 號 : 國 家 衛 生 研 究 院 EC1020502 號 樣 本 編 號 :( 訪 員 填 寫 )

More information

华恒家庭网关方案

华恒家庭网关方案 LINUX V1.5 1 2 1 2 LINUX WINDOWS PC VC LINUX WINDOWS LINUX 90% GUI LINUX C 3 REDHAT 9 LINUX PC TFTP/NFS http://www.hhcn.com/chinese/embedlinux-res.html minicom NFS mount C HHARM9-EDU 1 LINUX HHARM9-EDU

More information

C

C C 14 2017 5 31 1. 2. 3. 4. 5. 2/101 C 1. ( ) 4/101 C C ASCII ASCII ASCII 5/101 C 10000 00100111 00010000 ASCII 10000 31H 30H 30H 30H 30H 1 0 0 0 0 0 ASCII 6/101 C 7/101 C ( ) ( ) 8/101 C UNIX ANSI C 9/101

More information

組譯與連結(Ver6

組譯與連結(Ver6 Intel 8088/86 CPU GND 1 40 VCC GND 1 40 VCC A14 2 39 A15 AD14 2 39 AD15 A13 3 38 A16/S3 AD13 3 38 A16/S3 A12 4 37 A17/S4 AD12 4 37 A17/S4 A11 5 36 A18/S5 AD11 5 36 A18/S5 A10 A9 6 7 35 34 A19/S6 SS0 (

More information

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un Linux C July 27, 2016 Contents 1 Linux IDE 1 2 GCC 3 2.1 hello.c hello.exe........................... 5 2.2............................... 9 2.2.1 -Wall................................ 9 2.2.2 -E..................................

More information

浙江大学本科论文模板

浙江大学本科论文模板 本 科 生 毕 业 设 计 报 告 项 目 名 称 微 型 操 作 系 统 的 设 计 与 实 现 姓 名 与 学 号 曲 国 铖 3063027053 指 导 老 师 王 新 宇 专 业 计 算 机 科 学 与 技 术 学 院 计 算 机 学 院 A Dissertation Submitted to Zhejiang University for the Degree of Bachelor of

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha CYPOK CYPOK 1 UltraEdit Project-->Install Language Tool: Language Suite----->hi-tech picc Tool Name ---->PICC Compiler Executable ---->c:hi-picinpicc.exe ( Command-line Project-->New Project-->File Name--->myc

More information

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf (%d, & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf (%d %d 2013 18 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp, Compilation Error cin scanf Time Limit Exceeded 1: A 5 B 5 C 5 D 5 E 5 F 5 1 2013 C 1 # include 2 int main ( void ) 3 { 4 int cases, a, b,

More information

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2 (Guangzhou) AIT Co, Ltd 020-84106666 020-84106688 http://wwwlenxcn Xi III Zebra XI III 1 (Guangzhou) AIT Co, Ltd 020-84106666 020-84106688 http://wwwlenxcn 230V 110V [ ]! 2 (Guangzhou) AIT Co, Ltd 020-84106666

More information

C语言的应用.PDF

C语言的应用.PDF AVR C 9 1 AVR C IAR C, *.HEX, C,,! C, > 9.1 AVR C MCU,, AVR?! IAR AVR / IAR 32 ALU 1KBytes - 8MBytes (SPM ) 16 MBytes C C *var1, *var2; *var1++ = *--var2; AVR C 9 2 LD R16,-X ST Z+,R16 Auto (local

More information

Equal-Sign Directive C: #define MAX_SIZE 20 組語 (1): MAX_SIZE = 20 組語 (2): MAX_SIZE EQU <20> ; Cannot be redefined list BYTE 10,20,30,40 ListSize = ($

Equal-Sign Directive C: #define MAX_SIZE 20 組語 (1): MAX_SIZE = 20 組語 (2): MAX_SIZE EQU <20> ; Cannot be redefined list BYTE 10,20,30,40 ListSize = ($ 組語合法小抄 ASCII General-Purpose EAX accumulator EBX 好像很自由 ECX loop counter ESP stack pointer ESI, EDI index registers EBP extended frame pointer (stack) ( EIP instruction pointer (PUSH 會使 ESP 減小,POP 反之 )

More information

Ps22Pdf

Ps22Pdf ( ) ( 150 ) 25 15 20 40 ( 25, 1, 25 ), 1. A. B. C. D. 2. A. B. C. D. 3., J = 1 H = 1 ( A B, J', J, H ) A. A = B = 1, J' =0 B. A = B = J' =1 C. A = J' =1, B =0 D. B = J' = 1, A = 0 4. AB + AB A. AB B. AB

More information

Microsoft Word - 01.DOC

Microsoft Word - 01.DOC 第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的

More information