1 / 14

ICS 51 - Introductory Computer Organization

ICS 51 - Introductory Computer Organization. Review. Registers. Instructions. Data movement instructions Mov Arithmetic operations Add , Sub , Mul , Div Logical operations And , Or , Not , Xor , Shr , Shl Comparison instructions Cmp Control Transfer Instructions

nikita
Download Presentation

ICS 51 - Introductory Computer Organization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ICS 51 - Introductory Computer Organization Review

  2. Registers

  3. Instructions • Data movement instructions • Mov • Arithmetic operations • Add, Sub, Mul, Div • Logical operations • And, Or, Not, Xor, Shr, Shl • Comparison instructions • Cmp • Control Transfer Instructions • Unconditional: Jmp • Conditional: Jg, Jl, Jge, Jle, Jne

  4. Data Ranges and Data Types • Data Ranges • E.g. 4 bits: • Unsigned: from 0 to 15 • 1’s complement: from -7 to 7 • 2’s complement: from -8 to 7 • Data Types • Byte: 8 bits • Word: 16 bits • Dword: 32 bits

  5. Multiplication Operation • Unsigned multiplication: MUL • Code: MUL Operand • If Operand is a byte, e.g. MUL BL, thenAX = AL*Operand • If Operand is a word, e.g., MUL BX, thenDX:AX = AX*Operand • If Operand is a dword, e.g., MUL EBX, thenEDX:EAX = EAX*Operand • Signed multiplication: IMUL • (look up the code table)

  6. Division Operation • Unsigned division: DIV • Code: DIV Operand • If Operand is a byte, e.g. DIV BL, thenAL = AX/Operand AH = Rest • If Operand is a word, e.g., DIV BX, thenAX = DX:AX/Operand DX = Rest • If Operand is a dword, e.g., DIV EBX, thenEAX = EDX:EAX/Operand EDX = Rest • Signed division: IDIV • (look up the code table)

  7. Stack Push/Pop Examples • … run out of registersPush EAX //save EAX on the stackPush EBX //save EBX on the stack … use EAX and EBX for some calculations …Pop EBX //move top of the stack to EBXPop EAX //move top of the stack to EAX to restore its original value • Note the orders of PUSH and POP are reversed

  8. Function Call __declspec(naked) int add_func(int param1) { __asm{ PUSH ebx; PUSH ecx; // 1. Access param1 MOV ebx, dword ptr[esp+12]; MOV ecx, ebx; ADD ecx, 5; // 2. The return value should be placed in EAX MOV eax, ecx; POP ecx; POP ebx; // 3. Return to the caller RET; } } void main() { int result = 0; __asm{ PUSH eax; PUSH ebx; PUSH ecx; // 1. Pass parameter(s) to the procedure MOV ebx, 10; PUSH ebx; // 2. Execute call CALL add_func; // 3. Remove parameter(s) from the stack POP ebx; // 4. EAX has the return value MOV result, eax; POP ecx; POP ebx; POP eax; } }

  9. Function (cont.) void main() { int result = 0; __asm{ PUSH eax; PUSH ebx; PUSH ecx; // 1. Pass parameter(s) to the procedure MOV ebx, 10; PUSH ebx; // 2. Execute call CALL add_func; // 3. Remove parameter(s) from the stack POP ebx; // 4. EAX has the return value MOV result, eax; POP ecx; POP ebx; POP eax; } }

  10. Function (cont.) __declspec(naked) int add_func(int param1) { __asm{ PUSH ebx; PUSH ecx; // 1. Access param1 MOV ebx, dword ptr[esp+12]; MOV ecx, ebx; ADD ecx, 5; // 2. The return value should be placed in EAX MOV eax, ecx; POP ecx; POP ebx; // 3. Return to the caller RET; } }

  11. Number Systems • Decimal (10) • Binary (2) • Hexadecimal (16) • Octal (8) • Conversion between them

  12. Logical Operations • Get a bit • Using AND/OR • Count number of ones • Using DIV • Using AND and SHR • Mirror a byte

  13. Recursion • Recursion in computer programming is exemplified when a function is defined in terms of itself. • Base case • Recursive case • E.g. Factorial(n) as: • Base case: • n=0 or n=1: Factorial(n)= 1 • Recursive case: • n>1 : n * Factorial(n-1)

  14. Data Structures • Linked List • Element has • Value • Pointer to next element • Binary Search Tree • Element has • Value • Pointer to left child • Pointer to right child • Value of left subtree < root < right subtree • Insert and Traverse

More Related