Hi there guys!
Im here again asking for help. I have been reading the documentation of MASM32 of the editor but i cant get this one.
I have to ask the user a number for example: 6 and i have to print the multiply table of this number from 1 to 10
the result would be this:
6
12
18
24
30
36
42
48
54
60
Of course of my experience with other languaje i would use a FOR loop
But how you do this with in MASM32
Thanks a lot a lot for your supporte guys :)
just maintain a count in a register - ECX is often used as a count value
xor eax,eax
mov ecx,10
loop00: add eax,6
push ecx
push eax
print str$(eax),32 ;32 = space
pop eax
pop ecx
dec ecx
jnz loop00
EAX, ECX, EDX are volatile (destroyed across calls)
you could use EBX, ESI, or EDI - and eliminate the PUSH/POP, as they are preserved across calls
xor ebx,ebx
mov esi,10
.repeat
add ebx,6
print str$(ebx),32
dec esi
.until ZERO?
include \masm32\include\masm32rt.inc
.code
foo proc
LOCAL i:DWORD
mov i,1
.while i <= 10
imul eax,i,6
fnc crt_printf,"%d\n",eax
add i,1
.endw
ret
foo endp
main proc
invoke foo
inkey
exit
main endp
end main
Quote from: dedndave on October 16, 2014, 05:47:57 AM
just maintain a count in a register - ECX is often used as a count value
xor eax,eax
mov ecx,10
loop00: add eax,6
push ecx
push eax
print str$(eax),32 ;32 = space
pop eax
pop ecx
dec ecx
jnz loop00
EAX, ECX, EDX are volatile (destroyed across calls)
you could use EBX, ESI, or EDI - and eliminate the PUSH/POP, as they are preserved across calls
Hi there Im using your example and i would like to know how to do this
but with the user input ?
Thanks a lot
the attachment on this post should help
http://masm32.com/board/index.php?topic=1778.msg18390#msg18390 (http://masm32.com/board/index.php?topic=1778.msg18390#msg18390)
Or you can use the CRT scanf function to read the input, here packaged in a macro similar the MASM32 printf macro (but ANSI only):
;===============================================================================
include \masm32\include\masm32rt.inc
;===============================================================================
scanf MACRO format:REQ, args:VARARG
IFNB <args>
fn crt_scanf, cfm$(format), args
ELSE
fn crt_scanf, cfm$(format)
ENDIF
EXITM <>
ENDM
;===============================================================================
.data
i32 dd 0
f REAL8 ?
str1 db 24 dup(0)
.code
;===============================================================================
start:
;===============================================================================
printf("Enter an integer:")
scanf("%d", ADDR i32)
printf("%d\n",i32)
printf("Enter a float:")
;--------------------------------------------------------------
; For floating-point numbers scanf assumes REAL4 (type float),
; so to force a conversion to the REAL8 (type double) that
; printf expects, you must prefix the type field with "l"
; (a lower-case "L", and while upper-case worked in my test
; under Windows, lower-case is probably more universal among
; CRTs).
;--------------------------------------------------------------
scanf("%lf", ADDR f)
printf("%f\n",f)
printf("Enter string:")
;-----------------------------------------------------------
; For a string the optional field width (20 in the example)
; specifies the maximum number of characters that will be
; read from the field.
;-----------------------------------------------------------
scanf("%20s", ADDR str1)
printf("%s\n",ADDR str1)
inkey
exit
end start
;===============================================================================