#include <stdio.h>
#include <serial.h>
extern void echo(int conport, unsigned char esc_char);
int main()
{
int console = sys_get_console_dev(); /* find out current sys console */
int conport;
char escape;
switch (console) {
case COM1: conport = COM1_BASE;
break;
case COM2: conport = COM2_BASE;
break;
default: printf("Expected serial port for console, exiting\n");
return 0;
}
printf("Type escape character and enter\n");
if (scanf("%c\n", &escape) != 1)
escape = 0x01;
echo(conport, escape);
return 0;
}
I'm making an x86 program to basically just scan and output chars from an IO device, but I can't figure out how to use the in and out instructions correctly. I keep getting operand size mismatch and I've tried all the different sizes. The C code above is whats calling the x86 code below
.globl echo
.text
# first argument is int port, second argument is escape char
prologue:
push %ebp #push old ebp to top of stack
movl %esp, %ebp #point ebp to same thing as esp, both pointing to old ebp
#saving live registers
push %esi
push %edi
push %ebx
#take values from stack
movl 8(%ebp), %ebx #move connport int to ebx
movb 12(%ebp), %cl #move esc char to be counted to ecx
echo:
inb (%ebx), %dl #put input of conport ebx into dl
cmp %dl, %cl #cmp dl and esc char
je end #jmp to end if eq
outb %dl, (%ebx) #output %dl to conport
jmp echo
end:
pop %ebx
pop %edi
pop %esi
movl %ebp, %esp
pop %ebp
ret