CIS-77 Home http://www.c-jump.com/CIS77/CIS77syllabus.htm

Lab M13. Using Assembly with High-Level Languages


  1. Introduction
  2. Procedure Name Coordination
  3. Calling Conventions
  4. Example Calling ASM Procedure from C++
  5. M13_COPYSTR.ASM
  6. M13_main.cpp
  7. Missing MSVCR80.DLL or MSVCR80D.DLL
  8. Invoking COPYSTR Procedure from C++
  9. Quick Disassembly Examination of Executable Image
  10. Invoking a C Function from Assembly
  11. Building Your Own Stack Machine
  12. Stack Machine Example
  13. Stack Machine Memory
  14. Stack Machine Implementation
  15. Getting Started
  16. Additional Features and Improvements
  17. What to Submit
  18. Thursday 12/4/2008 lab: class demo in progress...

1. Introduction



2. Procedure Name Coordination



3. Calling Conventions



4. Example Calling ASM Procedure from C++




; The M13_COPYSTR.ASM file

.586P
.MODEL FLAT, stdcall ; Flat memory model
PUBLIC COPYSTR

_TEXT SEGMENT
; Procedure for copying the null-terminated source string to the target string.
;
; Input:
;   str_dest...Target string [ EBP + 08H ]
;   str_src....Source string [ EBP + 0CH ]
; Output:
;   EAX........address of the target string
;
; WARNING! target string length is unchecked
;
COPYSTR PROC  str_dest: DWORD, str_src: DWORD
        MOV   ESI, str_src  ; DWORD PTR [ EBP + 0CH ]
        MOV   EDI, str_dest ; DWORD PTR [ EBP + 08H ]
L1:
        MOV   AL, BYTE PTR [ESI]
        MOV   BYTE PTR [EDI], AL
        CMP   AL, 0
        JE    L2
        INC   ESI
        INC   EDI
        JMP   L1
L2:
        MOV   EAX, DWORD PTR [ EBP + 08H ]
        RET
COPYSTR ENDP
_TEXT ENDS
END



// The M13_main.cpp file

#include <iostream>

extern "C" int __stdcall COPYSTR( char*, char* );

int main()
{
    char destination[ 100 ] = { 0 };
    char* source = "Hello!";

    COPYSTR( destination, source );
    std::cout << destination;
    return 0;
}

5. Missing MSVCR80.DLL or MSVCR80D.DLL



6. Invoking COPYSTR Procedure from C++



7. Quick Disassembly Examination of Executable Image



8. Invoking a C Function from Assembly



9. Building Your Own Stack Machine



10. Stack Machine Example



11. Stack Machine Memory



12. Stack Machine Implementation



13. Getting Started



14. Additional Features and Improvements



15. What to Submit



16. Thursday 12/4/2008 lab: class demo in progress...