Well... "add eax, ebx" is right... Otherwise... no, you're not "doin' it right". :) You'd have to get "permission" to access the keyboard ports, and then... An interrupt is generated when a key is pressed - or released - and has to be "handled". Some keys result in more than one byte at port 60h, and in any case, the value read there would have to be translated (via lookup table) to get an ascii character value out of it. Really not the way you want to do it.
What you want to do is read/write from/to stdin/stdout. An extremely simple example that doesn't even prompt for input - just waits for input and spits it back...
global _start ; entrypoint - ld wants to know this
BUFSIZ equ 100 ; ought to be big enough
section .bss
buffer resb BUFSIZ
section .text
_start:
mov eax, 3 ; number for "sys_read"
mov ebx, 0 ; stdin
mov ecx, buffer ; address of buffer, not "[contents]"
mov edx, BUFSIZ ; maximum to read
int 80h ; call kernel
mov edx, eax ; sys_read returns length in eax
mov ecx, buffer
mov ebx, 1 ; stdout
mov eax, 4 ; "sys_write" - "__NR_write", actually
int 80h
mov ebx, 0 ; exit code
mov eax, 1 ; sys_exit
int 80h
Assemble with "nasm -f elf myfile.asm". Link with "ld -o myfile myfile.o". Run as "./myfile".
You can't exit with "ret", 'cause there's no return address on the stack - just "argc", a zero-terminated array of pointers to zero-terminated strings (command line args), followed by a zero-terminated array of pointers to zero-terminated strings (the environment variables). If you start your program with "main" and link it with gcc (the C startup code), then "main" is called, and you can "ret".
To actually add two numbers, we still have the job of converting the ascii string "123" into the number 123 (twice), adding them ("add eax, ebx"), the converting the resulting number in eax *back* to an ascii string so it can be displayed (this is the part where we can represent the number as binary, decimal, hex, octal, or whatever). This part isn't specific to Linux, and you should be able to find examples...
You probably want to look at
http://www.linuxassembly.org - mirrored here es
http://asm.sf.net - start with the Linuxassembly Howto, I guess. For more "general" asm information -
http://www.drpaulcarter.com/pcasm perhaps...
global _start
section .data
msg db "Welcome to Linux Assembly!, 10
msg_len equ $ - msg
section .text
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msg_len
int 80h
mov eax, 1
mov ebx, 0
int 80h
Warning: The lovely forum software is prone to "optimize" posts by removing spaces before periods etc. There's supposed to be a space between "section" and ".text", for example... in case you're not seeing it. Nasm does care.
Best,
Frank