;;; This program reads an integer limit then counts from 1 to the limt.
;;; Uses plain C I/O and must be linked to the C libraries.
;;; This version differs from count.s in that it keeps its data on the stack.
;; Frame pointer
;; Make space on the stack for the limit (ebp-4) and the
;; loop count (ebp-8)
;; Issue the prompt using printf.
;; Read the value using scanf.
lea eax, [ebp-4] ; EAX gets the address ebp-4.
push eax ; Put it onto the stack
push rfmt ; Other args and call.
;; Init the counter. The modifier dword specifies a 32-bit 1, and
;; is needed here because the assembler cannot otherwise determine
;; the intended size.
mov [ebp-8],dword 1
;; Loop test. Get the counter to eax, then compare to the limit.
ltop: mov eax,[ebp-8] ; Counter
cmp eax,[ebp-4] ; Limit
;; Print count. Use count value still in eax.
;; Increment the count
inc dword [ebp-8]
;; Back to the top
;; Pop the workspace off the stack, fix up frame pointer, leave.
finish: add esp,8
prompt: db 'Enter count: ',0
rfmt: db '%d',0
pfmt: db ' => %d',10,0