0

I have the following code in which I am trying to call an assembly function in C, which is trying to print "e" on the VGA Display (of QEmu):

void main()
{
 extern void put_in_mem();
 char c = 'e';
 put_in_mem(c, 0xA0);
}

The function put_in_mem is defined below:

.global _put_in_mem
_put_in_mem:
push bp
mov bp, sp
mov cx, [bp + 4]
mov ax, [bp + 6]
mov ax, 0xb800
mov ds, ax
mov [bx], cx
add bx, 0x1
mov cx, 0x7  
mov [bx], cx
pop bp
ret

When I compile the above assembly code using nasm I am getting the following error:

put_in_mem.asm:1: error: attempt to define a local label before any    non-local labels
put_in_mem.asm:1: error: parser: instruction expected

Why is this error coming?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
sarthak
  • 774
  • 1
  • 11
  • 27
  • `.global` aka `.globl` are GAS directives (https://sourceware.org/binutils/docs/as/Global.html), not NASM. [What is global \_start in assembly language?](https://stackoverflow.com/q/17898989) – Peter Cordes Jun 12 '22 at 22:39

1 Answers1

4

NASM gives special treatment to symbols beginning with a period. A label beginning with a single period is treated as a local label

NASM does have a global directive, but it's written without an initial period. So perhaps you meant to write global _put_in_mem

Michael
  • 57,169
  • 9
  • 80
  • 125