User Tools

Site Tools


notes:assembly

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
notes:assembly [2019/06/13]
leszek
notes:assembly [2019/06/23]
leszek [Data Types]
Line 21: Line 21:
 Data types supported by the x86 platform: Data types supported by the x86 platform:
  
-^  Data Type  ^  Bits  ^ +^  Data Type  ^  C++ Type  ^  Bits  ^ 
-| Byte | 8 | +| Byte | char | 8 |  
-| Word | 16 | +| Word | short | 16 | 
-| Doubleword | 32 | +| Doubleword ​int | 32 | 
-| Quadword | 64 | +| Quadword ​| long long | 64 | 
-| Quintword | 80 | +| Quintword ​| 80 | 
-| Double Quadword | 128 | +| Double Quadword ​| 128 | 
-| Quad Quadword | 256 |+| Quad Quadword ​| 256 |
  
 +
 +===== Examples =====
 +
 +==== Calculate Sum ====
 +
 +<code asm>
 +; Produce code for the flat memory model.
 +; Use C-style names for public symbols.
 +.MODEL FLAT, C
 +
 +; Memory block that contains executable code.
 +.CODE
 +
 +; The beginning of the procedure.
 +AsmCalcSum PROC
 +
 +; Function Prolog:
 +    push ebp                    ; save the EBP register on the stack
 +    mov ebp,​esp ​                ; copy ESP to EBP i.e., set EBP as the stack frame pointer
 +                                ; this enables access to the function'​s arguments
 +
 +; ESP always points to the stack'​s top-most item
 +; EBP is used as a base pointer to access data on the stack
 +
 +; Stack:
 +; High Memory ...
 +;             [ c ] = [ebp + 16]
 +;             [ b ] = [ebp + 12]
 +;             [ a ] = [ebp + 8]
 +;             [ret] = [ebp + 4] contains the return address
 +; Low Memory ​ [ebp] contains the old value of EBP pushed on the stack using push ebp
 +;                   this is the stack'​s top-most item pointed by ESP and EBP (because of mov ebp,esp)
 +
 +; Load the argument values.
 +    mov eax,[ebp + 8]           ; a --> EAX
 +    mov ecx,[ebp + 12]          ; b --> ECX
 +    mov edx,[ebp + 16]          ; c --> EDX
 +
 +; Calculate the sum.
 +    add eax,​ecx ​                ; eax += ecx
 +    add eax,​edx ​                ; eax += edx
 +
 +; An x86-32 assembly function must use EAX to return a 32-bit
 +; integer to its calling function.
 +
 +; Function Epilog:
 +    pop ebp                     ; restore the caller'​s stack frame pointer
 +    ret
 +
 +; The end of the procedure.
 +AsmCalcSum ENDP
 +
 +; The end of statements in the file.
 +    END
 +</​code>​
 +
 +<code c>
 +#include <​stdio.h>​
 +
 +extern "​C"​ int AsmCalcSum(int a, int b, int c);
 +
 +void CalcSum()
 +{
 +    int a = 17, b = 11, c = 14;
 +    int sum = AsmCalcSum(a,​ b, c);
 +    printf("​a = %d, b = %d, c = %d\n", a, b, c);
 +    printf("​sum = %d\n\n",​ sum);
 +}
 +</​code>​
  
  
Line 58: Line 127:
   * **Microarchitecture** defines the organization of a processor'​s internal components, including registers, execution units, instruction pipelines, data buses, and memory caches.   * **Microarchitecture** defines the organization of a processor'​s internal components, including registers, execution units, instruction pipelines, data buses, and memory caches.
   * In the **three-way superscalar design**, the processor is able to decode, dispatch, and execute three distinct instructions during each clock cycle.   * In the **three-way superscalar design**, the processor is able to decode, dispatch, and execute three distinct instructions during each clock cycle.
 +  * The address of **properly-aligned** data type is divisible by its size in bytes.
   * **SIMD** - Single Instruction Multiple Data   * **SIMD** - Single Instruction Multiple Data
  
notes/assembly.txt · Last modified: 2019/06/25 by leszek