can't input something in nasm using int 80h?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Basically I am learning Assembly language/nasm through this book : http://www.pravaraengg.org.in/Download/MA/assembly_tutorial.pdf



In the book one of the example is to do below tasks:




  1. output on the screen Please enter a number:

  2. ask user to input a number

  3. output on the screen saying: You have entered:1234


Below is the script:



section .data ;Data segment
userMsg db 'Please enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg ;The length of the message
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg
section .bss ;Uninitialized data
num resb 5
section .text ;Code Segment
global main
main:
;User prompt
mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Output the message 'The entered number is: '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
; Exit code
mov eax, 1
mov ebx, 0
int 80h


I am compiling the script at: https://rextester.com/l/nasm_online_compiler or https://www.jdoodle.com/compile-assembler-nasm-online



but I never get to input anything, it just straight outputs: Please enter a number: You have entered:










share|improve this question























  • Online compiler don't stop for reading an input. You have to tell them beforehand what you want them to take as input. And they ignore inputs from STDERR. Use STDIN instead: stackoverflow.com/a/51308591/3512216. Change mov ebx, 2 to mov ebx, 0.

    – rkhb
    Nov 16 '18 at 16:02




















0















Basically I am learning Assembly language/nasm through this book : http://www.pravaraengg.org.in/Download/MA/assembly_tutorial.pdf



In the book one of the example is to do below tasks:




  1. output on the screen Please enter a number:

  2. ask user to input a number

  3. output on the screen saying: You have entered:1234


Below is the script:



section .data ;Data segment
userMsg db 'Please enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg ;The length of the message
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg
section .bss ;Uninitialized data
num resb 5
section .text ;Code Segment
global main
main:
;User prompt
mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Output the message 'The entered number is: '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
; Exit code
mov eax, 1
mov ebx, 0
int 80h


I am compiling the script at: https://rextester.com/l/nasm_online_compiler or https://www.jdoodle.com/compile-assembler-nasm-online



but I never get to input anything, it just straight outputs: Please enter a number: You have entered:










share|improve this question























  • Online compiler don't stop for reading an input. You have to tell them beforehand what you want them to take as input. And they ignore inputs from STDERR. Use STDIN instead: stackoverflow.com/a/51308591/3512216. Change mov ebx, 2 to mov ebx, 0.

    – rkhb
    Nov 16 '18 at 16:02
















0












0








0








Basically I am learning Assembly language/nasm through this book : http://www.pravaraengg.org.in/Download/MA/assembly_tutorial.pdf



In the book one of the example is to do below tasks:




  1. output on the screen Please enter a number:

  2. ask user to input a number

  3. output on the screen saying: You have entered:1234


Below is the script:



section .data ;Data segment
userMsg db 'Please enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg ;The length of the message
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg
section .bss ;Uninitialized data
num resb 5
section .text ;Code Segment
global main
main:
;User prompt
mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Output the message 'The entered number is: '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
; Exit code
mov eax, 1
mov ebx, 0
int 80h


I am compiling the script at: https://rextester.com/l/nasm_online_compiler or https://www.jdoodle.com/compile-assembler-nasm-online



but I never get to input anything, it just straight outputs: Please enter a number: You have entered:










share|improve this question














Basically I am learning Assembly language/nasm through this book : http://www.pravaraengg.org.in/Download/MA/assembly_tutorial.pdf



In the book one of the example is to do below tasks:




  1. output on the screen Please enter a number:

  2. ask user to input a number

  3. output on the screen saying: You have entered:1234


Below is the script:



section .data ;Data segment
userMsg db 'Please enter a number: ' ;Ask the user to enter a number
lenUserMsg equ $-userMsg ;The length of the message
dispMsg db 'You have entered: '
lenDispMsg equ $-dispMsg
section .bss ;Uninitialized data
num resb 5
section .text ;Code Segment
global main
main:
;User prompt
mov eax, 4
mov ebx, 1
mov ecx, userMsg
mov edx, lenUserMsg
int 80h
;Read and store the user input
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h
;Output the message 'The entered number is: '
mov eax, 4
mov ebx, 1
mov ecx, dispMsg
mov edx, lenDispMsg
int 80h
;Output the number entered
mov eax, 4
mov ebx, 1
mov ecx, num
mov edx, 5
int 80h
; Exit code
mov eax, 1
mov ebx, 0
int 80h


I am compiling the script at: https://rextester.com/l/nasm_online_compiler or https://www.jdoodle.com/compile-assembler-nasm-online



but I never get to input anything, it just straight outputs: Please enter a number: You have entered:







assembly nasm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 15:46









asdfasdfasdfasdfasdfasdf

64




64













  • Online compiler don't stop for reading an input. You have to tell them beforehand what you want them to take as input. And they ignore inputs from STDERR. Use STDIN instead: stackoverflow.com/a/51308591/3512216. Change mov ebx, 2 to mov ebx, 0.

    – rkhb
    Nov 16 '18 at 16:02





















  • Online compiler don't stop for reading an input. You have to tell them beforehand what you want them to take as input. And they ignore inputs from STDERR. Use STDIN instead: stackoverflow.com/a/51308591/3512216. Change mov ebx, 2 to mov ebx, 0.

    – rkhb
    Nov 16 '18 at 16:02



















Online compiler don't stop for reading an input. You have to tell them beforehand what you want them to take as input. And they ignore inputs from STDERR. Use STDIN instead: stackoverflow.com/a/51308591/3512216. Change mov ebx, 2 to mov ebx, 0.

– rkhb
Nov 16 '18 at 16:02







Online compiler don't stop for reading an input. You have to tell them beforehand what you want them to take as input. And they ignore inputs from STDERR. Use STDIN instead: stackoverflow.com/a/51308591/3512216. Change mov ebx, 2 to mov ebx, 0.

– rkhb
Nov 16 '18 at 16:02














1 Answer
1






active

oldest

votes


















0














Works for me when I run it in a terminal on my Linux desktop, after linking it into a 32-bit static executable.



Oh, you're reading from stderr (fd=2), not stdin (fd=0). I noticed this when I tried piping input to it with echo 123 | ./foo and it didn't exit right away. (because stderr is still the terminal.) I checked to see that's what was really happening by running it with strace ./foo.



That happens to work when they're both open on the terminal, because by tradition stderr is opened read/write.





near dup: linux x86 assembly language sys_read call should have first argument as 0 (stdin)






share|improve this answer
























  • changing mov ebx, 2 to mov ebx, 0 seems to work, you might want to add that to your answer :)

    – asdfasdfasdf
    Nov 16 '18 at 17:06












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341174%2fcant-input-something-in-nasm-using-int-80h%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Works for me when I run it in a terminal on my Linux desktop, after linking it into a 32-bit static executable.



Oh, you're reading from stderr (fd=2), not stdin (fd=0). I noticed this when I tried piping input to it with echo 123 | ./foo and it didn't exit right away. (because stderr is still the terminal.) I checked to see that's what was really happening by running it with strace ./foo.



That happens to work when they're both open on the terminal, because by tradition stderr is opened read/write.





near dup: linux x86 assembly language sys_read call should have first argument as 0 (stdin)






share|improve this answer
























  • changing mov ebx, 2 to mov ebx, 0 seems to work, you might want to add that to your answer :)

    – asdfasdfasdf
    Nov 16 '18 at 17:06
















0














Works for me when I run it in a terminal on my Linux desktop, after linking it into a 32-bit static executable.



Oh, you're reading from stderr (fd=2), not stdin (fd=0). I noticed this when I tried piping input to it with echo 123 | ./foo and it didn't exit right away. (because stderr is still the terminal.) I checked to see that's what was really happening by running it with strace ./foo.



That happens to work when they're both open on the terminal, because by tradition stderr is opened read/write.





near dup: linux x86 assembly language sys_read call should have first argument as 0 (stdin)






share|improve this answer
























  • changing mov ebx, 2 to mov ebx, 0 seems to work, you might want to add that to your answer :)

    – asdfasdfasdf
    Nov 16 '18 at 17:06














0












0








0







Works for me when I run it in a terminal on my Linux desktop, after linking it into a 32-bit static executable.



Oh, you're reading from stderr (fd=2), not stdin (fd=0). I noticed this when I tried piping input to it with echo 123 | ./foo and it didn't exit right away. (because stderr is still the terminal.) I checked to see that's what was really happening by running it with strace ./foo.



That happens to work when they're both open on the terminal, because by tradition stderr is opened read/write.





near dup: linux x86 assembly language sys_read call should have first argument as 0 (stdin)






share|improve this answer













Works for me when I run it in a terminal on my Linux desktop, after linking it into a 32-bit static executable.



Oh, you're reading from stderr (fd=2), not stdin (fd=0). I noticed this when I tried piping input to it with echo 123 | ./foo and it didn't exit right away. (because stderr is still the terminal.) I checked to see that's what was really happening by running it with strace ./foo.



That happens to work when they're both open on the terminal, because by tradition stderr is opened read/write.





near dup: linux x86 assembly language sys_read call should have first argument as 0 (stdin)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 15:55









Peter CordesPeter Cordes

135k19204345




135k19204345













  • changing mov ebx, 2 to mov ebx, 0 seems to work, you might want to add that to your answer :)

    – asdfasdfasdf
    Nov 16 '18 at 17:06



















  • changing mov ebx, 2 to mov ebx, 0 seems to work, you might want to add that to your answer :)

    – asdfasdfasdf
    Nov 16 '18 at 17:06

















changing mov ebx, 2 to mov ebx, 0 seems to work, you might want to add that to your answer :)

– asdfasdfasdf
Nov 16 '18 at 17:06





changing mov ebx, 2 to mov ebx, 0 seems to work, you might want to add that to your answer :)

– asdfasdfasdf
Nov 16 '18 at 17:06




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341174%2fcant-input-something-in-nasm-using-int-80h%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine