百度网盘下载地址:
https://pan.baidu.com/s/1_-IznMWL3z1CROziiD6mCw
c++ 与 汇编 举例
汇编代码:
#delay.s
.globl _delay, _printinfo
.extern _printf, _count
.data
str: .string "Nop count is %x\n"
.text
_delay: # int delay (int count);
mov 4(%esp), %ecx
mov %ecx, %eax
1: nop
loop 1b
mov %eax, _count
ret
_printinfo: # void printinfo (void);
mov _count, %eax
push %eax
push $str
call _printf
add $8, %esp
ret
c++代码:
//test.cpp
extern "C" {
#include <stdio.h>
unsigned int count;
int delay (int count);
void printinfo (void);
class Myclass {
public:
virtual void myfun (void) = 0;
};
class Youclass : public Myclass {
public:
void myfun (void) {
// printinfo ();
printf ("`O`");
delay (0xfffff);
}
void youfun (void) ;
};
void Youclass :: youfun (void) {
printf (",M,");
delay (0xaffff);
}
int main (void) ;
}
int main (void) {
Youclass you;
unsigned short int i = 0x2f;
while (i--) {
you.myfun();
printf ("^A^");
delay (0xbffff);
printf (".B.");
delay (0x9ffff);
you.youfun();
}
}
编译方法:
as -o delay.o delay.s
g++ -o test.o test.cpp -c
g++ test.o delay.o
效果图: