I am new to Assembler and am currently reading a book about it by Jonathan Bartlett called ‘Learn to Program with Assembly’. On pages 160-1 he gives the following sample program to demonstrate the use of the STDIN and STDOUT features of C/C++ in GAS Assembler:
.globl main
.section .data
promptformat: .ascii "Enter two numbers separated by spaces, then press RETURN.n"
scanformat: .ascii "%d %d"
resultformat: .ascii "The result is %d.n"
.section .text
.equ LOCAL_NUMBER, -8
.equ LOCAL_EXPONENT, -16
main:
enter $16, $0
# PROMPT THE USER FOR INPUT
movq stdout, %rdi
movq $promptformat, %rsi
movq $0, %rax
call fprintf
# READ IN DATA AND PERFORM CALCULATION
movq stdin, %rdi
movq $scanformat, %rsi
leaq LOCAL_NUMBER(%rbp), %rdx
leaq LOCAL_EXPONENT(%rbp), %rsi
call exponent
# OUTPUT RESULT FOR USER
movq stdout, %rdi
movq $resultformat, %rsi
movq %rax, %rdx
movq $0, %rax
call fprintf
leave
ret
When I run the program, the STDOUT giving the prompt works just fine, but when I type in the two integers and hit ENTER, the program does nothing until I am forced to exit with Ctrl-C. It’s as though the program is waiting for some type of end-of-line character or something.
(NOTE: This program also calls another program named ‘exponent’ which is not shown here. If anyone thinks it’s necessary, I can post that code, too. Honestly, though, I don’t think the exponentscanf program is making it that far anyway.)
I am running Linux Mint-Virginia, and the program is being compiled with GNU: gcc -static exponentscanf.s exponentfunc.s -o exponentscanf
.
[I think I just addressed this point above.]
Digital Samizdat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.