How to take in multiple inputs from user in assembly -
i'm pretty new assembly. know how take in 1 value user, if want user input 3 numbers separated spaces.
i'm trying store each of them separate register, this.
push qword 0 ;make space 8-byte number push qword 0 ;make space 8-byte number push qword 0 ;make space 8-byte number mov qword rdi, formatfloatinput mov qword rsi, rsp mov qword rax, 0 call scanf pop qword r15 ;pop value stack r15 pop qword r14 ;pop next value in stack r14? pop qword r13 ;pop next value in stack r13?
sample input: 13 15 36
now r15
should contain 13, r14
contains 15 , r13
contains 36.
the c equivalent scanf("%ld %ld %ld", &r15, &r14, &r13)
. notice have pass 3 pointers, each of output variables. pass 1. also, formatfloatinput
misleading, reading integer registers, need integer format. should work:
push qword 0 ;make space 8-byte number push qword 0 ;make space 8-byte number push qword 0 ;make space 8-byte number mov qword rdi, format mov qword rsi, rsp ; &r15 lea rdx, [rsp+8] ; &r14 lea rcx, [rsp+16] ; &r13 mov qword rax, 0 call scanf pop qword r15 ;pop value stack r15 pop qword r14 ;pop next value in stack r14? pop qword r13 ;pop next value in stack r13? .... format: db "%ld %ld %ld", 0
pushing , popping not usual way write this, isn't wrong such. remember keep stack aligned if calling convention requires that.
Comments
Post a Comment