Would you tell me how to do ? [SOS] C++ ->ASM
我想将下面程式中的init_port和send_port改成汇编。但我不识汇编,你能帮个忙吗?因我在Delphi 5.x开发了一个系统,在Delphi 5.x可使用ASM。
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
#include <bios.h>
void init_port(code)
unsigned char code;
{
union REGS r;
r.x.dx = 0; /* com1 */
r.h.ah = 0;
r.h.al = code;
int86(0x14,&r,&r);
}
void send_port(c)
char c;
{
union REGS r;
r.x.dx = 0; /* com1 */
r.h.al = c;
r.h.ah = 1;
int86(0x14,&r,&r);
if (r.h.ah & 128) {
printf("send error !\n");
exit(-1);
}
}
/************************/
void setmode(mode)
int mode;
{
send_port(27);
if (mode==1) send_port(17); /* mode 1: overwrite mode */
if (mode==2) send_port(18); /* mode 2: overwrite mode */
if (mode==3) send_port(19); /* mode 3: overwrite mode */
}
void cleardisplay()
{
send_port(12);
}
void initdisplay()
{
send_port(27);
send_port(64);
}
void writestring(cc)
char *cc;
{
int i,len;
len=strlen(cc);
send_port(27);
send_port(81);
send_port(65);
for (i=0;i<=len;i++) {
send_port(toascii(cc[i]));
}
send_port(13);
}
void setstatus(s1,s2,s3,s4,s5)
int s1,s2,s3,s4,s5;
{
send_port(27);
send_port(81);
send_port(67);
send_port(s1+0x30);
send_port(s2+0x30);
send_port(s3+0x30);
send_port(s4+0x30);
send_port(s5+0x30);
send_port(13);
}
void setpoint(k,n)
int k,n; /* n=1 On, n=0 Off 1=<k<=11 */
{
send_port(27);
send_port(46);
send_port(k);
send_port(n);
}
void statusonly(k,n)
int k,n; /* n=1 On, n=0 Off 1=<k<=5 */
{
send_port(27);
send_port(115);
send_port(k);
send_port(n);
}
void setcursor(n)
int n; /* n=1 On, n=0 Off */
{
send_port(27);
send_port(95);
send_port(n);
}
void cursormlr(kk)
int kk;
{
send_port(27);
send_port(91);
if (kk==1) send_port(67); /* kk=1 right move, kk=-1 left move */
if (kk==-1) send_port(68);
}
void cursormud(kk)
int kk;
{
send_port(27);
send_port(91);
if (kk==1) send_port(65); /* kk=1 up move, kk=-1 down move */
if (kk==-1) send_port(66);
}
void leftmost()
{
send_port(27);
send_port(91);
send_port(76);
}
void rightmost()
{
send_port(27);
send_port(91);
send_port(82);
}
void cursorhome()
{
send_port(27);
send_port(91);
send_port(72);
}
void cursorbottom()
{
send_port(27);
send_port(91);
send_port(75);
}
void cursormove(x,y)
int x,y; /* 1<=x<=11, y=1 */
{
send_port(27);
send_port(108);
send_port(x);
send_port(y);
}
/*****************************/
void main()
{
void aaaa();
int i;
init_port(251);
/*255 ff 251 f */
printf(" clear screen! press any key\n");
getch();
cleardisplay();
cursorhome();
printf("display '1.23456789013',press any key\n");
getch();
writestring("1.23456789013");
printf("display 'ABCDEFGHIJKLN',press any key\n");
getch();
writestring("ABCDEFGHIJKLN"); /* string */
printf("display 'QPQRSTUVWXYZ.+',press any key\n");
getch();
writestring("OPQRSTUVWXYZ.+"); /* string */
printf("display '-=QRSTUVWXYZ.+',press any key\n");
getch();
writestring("-=QRSTUVWZXYZ.+"); /* string */
aaaa();
}
void aaaa()
{
int i;
printf("cursor to home,press any key\n");
getch();
cursorhome();
printf("clear screen!,press any key\n");
getch();
cleardisplay();
printf("display 5 kinds of status LED,press any key\n");
getch();
setstatus(1,0,0,0,0); /* status */
delay(500);
setstatus(0,1,0,0,0);
delay(500);
setstatus(0,0,1,0,0);
delay(500);
setstatus(0,0,0,1,0);
delay(500);
setstatus(0,0,0,0,1);
delay(500);
printf("clear sreen and set cursor to position 1\n");
getch();
cleardisplay();
setcursor(1);
printf("display point! press any key\n");
getch();
for (i=1;i<13;i++) {
setpoint(i,1);
delay(1500);
setpoint(i,0);
}
for (i=12;i>0;i--) {
setpoint(i,1);
delay(1500);
setpoint(i,0);
}
printf("clear screen and display '888888888888' !\n");
printf("cursor to home and 5 kinds of status LED on, press any key\n");
getch();
cleardisplay();
cursorhome();
writestring("888888888888\n");
setstatus(1,1,1,1,1);
printf("move cursor,press any key\n");
getch();
for (i=1;i<13;i++)
{
cursorhome();
setcursor(i);
delay(1500);
cleardisplay();
}
printf("press any to exit!");
getch();
}