/******************************************************* * File: one2N.s * Date: Sep 29, 2021 * Author: DSS * Assembler: as under the gcc compiler * Purpose: print integers 1 thru a user-provided value N *******************************************************/ .globl main main: push %rbp # keep stack aligned #Get how many to print from user mov $0, %rax # clear AL (zero FP args in XMM registers) leaq prompt(%rip), %rdi # load format string to proper register call printf # print it # Read int leaq fmt_in(%rip), %rdi # load format string leaq nums(%rip), %rsi # set storage to address of x call scanf /* Uncomment to echo value read; must uncomment res: below xor %rax, %rax # Another way to 0 out %rax; leaq res(%rip), %rdi # load format string movq nums(%rip), %rsi# must load value from memory!! movq %rsi, %r14 call printf */ # Load value from memory movq nums(%rip), %rsi movq %rsi, %r14 # Load value to print to unused register # Originally used %r10 for value but it got clobbered mov $0, %r12 #put value in reg r12 loop: inc %r12 #inc value # printf(format,nextValue); # Put format string in %rdi, variable corresponding to %d in 01 # then call printf function mov $format, %rdi mov %r12,%rsi #put value in %rsi for output xor %rax, %rax #must 0 out %rax call printf #print it cmp %r14w,%r12w #compare counter with numInts; just lowest word (why?) jl loop #if reg values were unequal (ctr#=numInts), iterate done: pop %rbp ret .data format: .asciz "%d\n" fmt_in: .string "%d" prompt: .asciz "Print values ending with? >" nums: .long 0 # res: .string "Read:%d\n" Uncomment with echo value code above