pk_fox wrote: M-Saunders wrote:
Ah yes, the limit was due to using word sizes. Change this bit of the code (in lib_print_number):
- Code: Select all
mov eax, 0 ; Start converting number to ASCII
mov word ax, [loopctr]
- Code: Select all
mov dword eax, [loopctr]
As for passing the limit as a parameter, yep, that's also doable. But bear in mind that the limit number will be passed as an ASCII text string, so you can't use it directly. Instead, you need to convert it from a string to a proper number; there's code for this in lib_input_number in library.asm.
Give it a try, good luck, and let me know if you need any help!
Cheers Mike, I do appreciate your help, how do you know what registers to put what in ( if that makes sense ) I've downloaded a few articles from the web and none of them state in muppet terms "this must go in eax","this must be a dword" etc etc... I'm finding it difficult to self help ( I'm sure you dont want me bugging you every day ) ]'m a pro dev of long standing but never got involved with assembler as I never had a need to ( nor do I now but it's fascinating ) keep up the tutorials !!
Me again !, can't get lib_input_number to play ball
this is what I've tried
mov dword [loopctr],0
;mov dword [looplimit],100
pop ebx ; argc (argument count)
pop ebx ; argv (argument 0, the program name)
pop ebx ; The first real arg, a filename
pop ebx ; extra pop for looplimit param
mov [buffer],ebx ; then move it to your buffer var
mov [looplimit],eax ; is this correct ? where is the converted number held ?
; rest of the code unchanged.
; modded lib_input_number
;mov edi, buffer ; already populated by me
;call lib_input_string ; don't need this call ?
mov esi, buffer ; buffer has the last popped ebx
mov eax, 0 ; Initialise accumulator
mov ebx, 10 ; Decimal-system's radix
mov cl, [esi] ; Fetch next character
cmp cl, '0' ; Char preceeds '0'?
jb .invalid ; Yes, not a numeral
cmp cl, '9' ; Char follows '9'?
ja .invalid ; Yes, not a numeral
mul ebx ; Ten times prior sum
and ecx, 0x0F ; Convert char to int
add eax, ecx ; Add to prior total
inc esi ; Advance source index
jmp .next_digit ; And check another char
mov long [tmp], eax ; Get EAX back after popa
mov long eax, [tmp]
sorry to be a pain