0

I would like to ask about making feedline in NASM assembler. At this moment we create simple programs in university.

When I wanted make endline before, I just declared byte and overwrote "0ah" inside. Something like that:

section .text
global _start

_start:

mov eax,4
mov ebx,1
mov ecx,variable
mov edx,1

section .data
variable db 0ah

It works, but takes long time. So I wanted writing "0ah" directly into register, without initialize variable, in this way:

section .text
global _start

_start:

mov eax,4
mov ebx,1
mov ecx,10 ;; hexadecimal 0ah
mov edx,1

But it doesn't works. I would ask for help.

Ps. If anyone have some time, check please my previous thread about registers working: Binary representation in processor's registers in Nasm

Community
  • 1
  • 1
Plusce
  • 117
  • 2
  • 14

1 Answers1

0

You could use .data section for string values you want to use like \n or other strings you want to use and the use C function printf and scanf to deal with IO. Just add:

extern  printf, scanf

at the beginning of your asm file, then:

section .data
   input_n db  'n = ',0
   number   db  '%d',0   
   endofline   db  10,0 

And call printf like this in the .text section:

mov eax,endofline
push    eax
call    printf
add esp,8

To compile, a Makefile like:

main: main.o factorial.o 
    gcc -o main main.o facto.o

%.o: %.asm
    nasm -f elf $^

clean:
    rm -f a.out core *.o *~ main

where main.asm will be your main asm program and factorial.asm and other cotaining let's say factotial function in nasm

Gerard Rozsavolgyi
  • 4,834
  • 4
  • 32
  • 39