first of all, i am using windows xp, and i am using nasm to assemble my code, and djgpp to compile it with driver.c

what i basically want to do is do a chat thing using serial ports, pretty much like Choink23 is trying to do in another thread.

here's the code i've done so far:

segment .text
global _asm_main

_asm_main:
enter 0,0
pusha

mov dx, 0               ;send 'a' through com1
mov al, 'a'
mov ah, 1
int 14h

mov ah,3               ;check serial port status
int 14h                   ;to check if data is available

shr ax,9               ;puts bit8 to the carryflag
jc fetch                 ;if bit8=1, fetch
jnc cont               ;data is not available

fetch:
mov dx, 1            ;receives 'a' from com2
mov ah, 2
int 14h

mov dl, al            ;prints the received charac
mov ah, 02h
int 21h

cont:
popa
mov eax, 0
leave
ret

this code is not printing anything! i'm not sure if something's wrong with the cable, or something's wrong in the backside of my cpu, or something's wrong with my code. pls help me! thanks

i wrote this code:

segment .text
global _asm_main

_asm_main:
enter 0,0
pusha

mov dx,0   ;send 'a' through com1
mov al,'a'
mov ah,1
int 14h
test ah,80h ;got this thing from ArtofASM
jnz error

error:
mov ah,02
mov dl,'e'
int 21h

popa
mov eax,0
leave
ret

and when i ran it, it printed e! so does this means something's wrong with my hardware?

this chat thing should be between 2 computers, but since i only have one computer, i just plugged one end of the serial cable to com1, and the other end to com2..

oh my i just found out that attaching the cable to com1 and the other to com2 to test my code is wrong!

i found out that what i need to do is attach it to com1 and short of short-circuit pins 2 and 3! (i am using a "cross" serial cable, this being specified in our project specifications, including how a cross serial cable looks like)

how do you do that? do i have to stick some piece of metal both on pins 2 and three?

http://www.beyondlogic.org/serial/termpoll.c

above is a code from beyondlogic. i would like to basically translate this code into assembly. i would like to interface c and assembly, having inportb and outportb written in c, and the two fuction being called in asm.

can you pls. give me references on how i could write those functions in c?

The major problem you fase is the operating system you plan to use. MS-Windows and *nix will not permit programs to access the ports directly like that program you posted. Only MS-DOS will permit it.

Search some of these google links to see it they contain anything useful to you.

WHAT IS WRONG WITH THIS CODE? It's not printing anything..

i am compiling using gcc in ms-dos, and is using nasmide to assemble, which is on ms-dos as well..

%define port1 3f8h

segment .data
char dw 'a', 0
format dw "%s", 0

segment .text
global _asm_main
extern _outportb, _inportb, _printf

_asm_main:
enter 0,0
pusha

push char ;send character to port1
push port1
call _outportb
add esp, 8

push port1 ;receive char from port1
call _inportb
add esp, 4

;mov edx, eax ;print received char
;mov ah, 02h ;using assembly
;int 21

; i tried either way, it's not working

push eax ;print using printf
push format
call _printf
add esp, 8

popa
leave
mov eax, 0
ret

i am linking this code with these C code for the inport/outport functions

#include <stdio.h>
#include <dos.h>

int main()
{
int ret_status;
ret_status = asm_main();
return ret_status;
}

thanks..

edit: also, the termpoll.c is running perfectly in my pc, i ran it on dos. i really dont understand why my asm translation is not working.. i'm stuck

This article has been dead for over six months. Start a new discussion instead.