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
notes:assembly [2019/06/14]
leszek [Data Types]
notes:assembly [2019/06/25]
leszek [Links]
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 ===== ===== Examples =====
  
-<​code ​asm86>+==== Calculate Sum ==== 
 + 
 +<​code ​asm>
 ; Produce code for the flat memory model. ; Produce code for the flat memory model.
 ; Use C-style names for public symbols. ; Use C-style names for public symbols.
-.MODEL FLAT,C+.MODEL FLAT, C
  
 ; Memory block that contains executable code. ; Memory block that contains executable code.
Line 46: Line 48:
 ; Function Prolog: ; Function Prolog:
     push ebp                    ; save the EBP register on the stack     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+    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 ; ESP always points to the stack'​s top-most item
Line 57: Line 60:
 ;             [ a ] = [ebp + 8] ;             [ a ] = [ebp + 8]
 ;             [ret] = [ebp + 4] contains the return address ;             [ret] = [ebp + 4] contains the return address
-; Low Memory ​ [ebp] contains the old value of EBP pushed using push ebp; this is the stack'​s top-most item pointed by ESP and EBP (because of mov ebp,esp)+; 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. ; Load the argument values.
Line 80: Line 84:
 ; The end of statements in the file. ; The end of statements in the file.
     END     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>​ </​code>​
  
Line 115: Line 133:
 ===== Links ===== ===== Links =====
  
 +  * [[https://​web.itu.edu.tr/​kesgin/​mul06/​intel/​index.html|Intel Instruction Set Pages]]
   * [[https://​www.cs.virginia.edu/​~evans/​cs216/​guides/​x86.html|x86 Assembly Guide]]   * [[https://​www.cs.virginia.edu/​~evans/​cs216/​guides/​x86.html|x86 Assembly Guide]]
   * [[http://​www.cs.virginia.edu/​~evans/​cs216/​guides/​vsasm.html|Guide to Using Assembly in Visual Studio .NET]]   * [[http://​www.cs.virginia.edu/​~evans/​cs216/​guides/​vsasm.html|Guide to Using Assembly in Visual Studio .NET]]
notes/assembly.txt · Last modified: 2019/06/25 by leszek