NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: assistech on April 26, 2020, 01:41:33 PM
-
Hi,
After to hit a value for a "call _scanf", how could you keep or use it for other operations ?
%include "io.inc"
extern _printf
extern _scanf
extern _puts
section .data
msg dd 'The number is %d',13,10,0
section .text
global CMAIN
CMAIN:
mov ebp,esp;
push eax
push msg
call _puts
NEWLINE
call _scanf
add esp,16
xor eax,eax
ret
-
What have you tried?
I believe "scanf" should take a format string and one or more pointer arguments. Try
man 3 scanf" (or however you do it in your OS). The result should be where you tell it to be.
Best,
Frank
-
Hi,
I would like "2" in a variable "i" for storing it after scanf ?
like (C program):
int main(void)
{
int i;
char c;
printf("your score \n");
scanf("%d",&i);
printf("this is your score %d",i);
c=getchar();
}
-
W hat have you tried? What happened?
Best,
Frank
-
Hi sorry, my question is very simple maybe bad explanation sorry for that:
In my first program after "call _scanf", i would like to store the value in variable for another exploitation.
Please
-
Maybe print it again with call _printf
-
my question is very simple
So is mine:
What have you tried?
Best,
Frank
-
Can you write this simple C program in Assembler please:
int main(void)
{
int i;
char c;
printf("your score \n");
scanf("%d",&i);
printf("this is your score %d",i);
c=getchar();
}
*NB: i will happy to understand how you take out "i".....
-
Have you understand ? After to hit my value with _scanf, i would like to display it again at screen
-
I have another question. If you're not willing to put any effort into this, why should I?
Oh alright... you did say "please"...
This is for Linux. I'm not going back to Windows even if you say 'Pretty please with sugar on it'!
The "--prefix _" should put underscores on "main", "scanf", and "printf" and make it work for 'doze. I hope...
I made "t" a global variable, not local/automatic as your C program showed. Simpler, IMO. If you want it local, TRY IT!
; Linux nasm -f elf32 prog.asm
; 'doze nasm -f win32 --prefix _ prog.asm
; gcc -m32 -o prog(.exe) prog.o
global main
extern scanf
extern printf
section .text
main:
push ebp
mov ebp, esp
push t
push fmt
call scanf
push dword [t]
push fmt
call printf
mov esp, ebp
pop ebp
ret
fmt db "%d", 0
section .bss
t resd 1
Best,
Frank
-
Hi, thanks
Yes, i'm doing efforts, but sometimes i need to compare experiment codes. Now, i have more skill.... Thanks
But something have no explanation like this :
1- push dword[t] ???? (What is "dword[---]" ?), is it a Pointer ??
Is dword point on one word, if i have a string like "good morning", can i use dword[t] ?
-
"dword" is the size. "doubleword" - 4 bytes - 32 bits
If you used it on your string.you would get only the 4 bytes "good", Probably not what you want.
Best,
Frank
-
Hi,
Have you ever use "scanf" with NASMX ? Will write like it : INVOKE message,scanf
Thanks
-
I don't think so. I don't know much about NASMX and rarely use the C library...
Best,
Frank
-
Ok,
You never use "procedure", "structure" ??
-
"structure" yes (rarely). "procedure"... probably not.
Best.
Frank