Sunday, July 12, 2009

Can someone help me translate this C code to 32 bit assembly program?

The program simply allows two computer connected together using a "cross" serial cable.Tthe program should accept a key-press from a user and automatically sends the character to the other computer screen. The other computer should be able to do the same.


Can you please help me convert it? I am not familiar with assembly programming. Thanks!





#include %26lt;dos.h%26gt;


#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;





#define PORT1 0x3F8





void main(void)


{


int c;


int ch;


outportb(PORT1 + 1 , 0);


outportb(PORT1 + 3 , 0x80);


outportb(PORT1 + 0 , 0x03):


outportb(PORT1 + 1 , 0x00);


outportb(PORT1 + 3 , 0x03);


outportb(PORT1 + 2 , 0xC7);


outportb(PORT1 + 4 , 0x0B);





printf("\nSample Comm's Program. Press ESC to quit \n");





do { c = inportb(PORT1 + 5);


if (c %26amp; 1) {ch = inportb(PORT1);


printf("%c",ch);}


if (kbhit()){ch = getch();


outportb(PORT1, ch);}


} while (ch !=27);


}

Can someone help me translate this C code to 32 bit assembly program?
Gopinath M is right but if you want to do it the hard way here's a rough guide





;Set Up Comm port parameters





Mov DX,03F9


Mov AL,00


Out AL,DX


Mov DX,03FB


Mov AL,80


Out AL,DX


Mov DX,03F8


Mov AL,03


Out AL,DX


Inc DX


Mov AL,00


Out AL,DX


Inc DX


Mov AL,03


Out AL,DX


Inc DX


Mov AL,C7


Out AL,DX


Inc DX


Mov AL,0B


Out AL,DX





:loop1


; Wait for key pressed and get Character/scancode from Keyboard


Mov AX,0010


INT 16


;Scancode/ASCII returned in AX





;Test for Esc scancode jump to end if true


Mov BL,01


CMP AH,BL


JZ ; jump to end address





;If ASCII non-zero then output to COM port


Mov BL,00


CMP AL,BL


JZ :Loop1 ;if ASCII = 0 go back for new input





Mov DX,03F8


Out AL,DX


JMP :Loop1





:End
Reply:E=MC2
Reply:instead of manually creating the same project in assembly.





you have lots of C compilers that can provide 32 bit exe file
Reply:Alternatively you can consult an assembly expert. Check websites like http://getafreelnacer.com/


No comments:

Post a Comment