News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Challenge: Print 0 ... 100 without loop or recursion

Started by jj2007, July 15, 2019, 07:44:53 PM

Previous topic - Next topic

jj2007

A simple challenge for the newcomers: Print the numbers from 0 ... 100 without using a loop and without recursion. Here is a template to get you started:

include \masm32\include\masm32rt.inc

.code
start: mov ecx, 0
; .Repeat ; sorry, looping is not allowed!!!
print str$(ecx), " " ; this prints just one "0" followed by a blank
; .Until 0

MsgBox 0, "That was perfect!!", "Success:", MB_OK
exit
end start


@José: That one is not meant for you :badgrin:

HSE

I have not problem to wait newcomers' solutions! (because I don't have idea  :biggrin:)
Equations in Assembly: SmplMath

mabdelouahab


include \masm32\include\masm32rt.inc

.code
start: mov ecx, 0
; .Repeat ; sorry, looping is not allowed!!!
print str$(0), "." ; this prints just one "0"
print str$(1), "." ; this prints just one "1"
print str$(2), "." ; this prints just one "2"
...
print str$(100), " " ; this prints just one "100" followed by a blank
; .Until 0

MsgBox 0, "That was perfect!!", "Success:", MB_OK
exit
end start

:biggrin:

jj2007

include \masm32\include\masm32rt.inc

.code
start: print "0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99"
MsgBox 0, "THAT was perfect!! (but you were pretty close, mabdelouahab)", "Success:", MB_OK
exit
end start
:badgrin:

aw27

Very good JJ  :thumbsup:

Even better, from 0 to 1000:


.model flat, stdcall

includelib msvcrt.lib
printf proto C :ptr, :vararg

.data
nums label dword
counter=0
WHILE counter LE 1000
db "%d "
counter = counter +1
ENDM
db 0
oldesp dword 0
align 16
stacked dd 1000h dup (0)
stacker label dword

counter=0
WHILE counter LE 1000
DWORD counter
counter = counter +1
ENDM

.code

main proc
mov oldesp, esp
mov esp, offset stacker
invoke printf, offset nums
mov esp, oldesp
ret
main endp

end


daydreamer

I was thinking I am a student that just learned about boolean NOT,AND,OR,XOR and binary numbers
cout << "000 001 010 011 100";
:greenclp:
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

hutch--

What's the challenge ?

print 1
print 2
print 3
  ........
print 99
print 100

You guys must be bored.

jj2007

Quote from: AW on July 16, 2019, 04:02:07 AM
Very good JJ  :thumbsup:

Thanks :badgrin:

(but your WHILE counter LE 1000 is cheating - that's a loop  :smiley:)

Quote from: hutch-- on July 16, 2019, 04:48:32 AM
You guys must be bored.

Yep, that explains it all :thumbsup:

morgot

Sorry for the bad English

jj2007

Yes, Morgot. If it doesn't provide a loop, of course ;-)

aw27

Quote from: jj2007 on July 16, 2019, 07:53:44 AM
[(but your WHILE counter LE 1000 is cheating - that's a loop  :smiley:)

It is exactly the same as this:

Quote from: jj2007 on July 16, 2019, 01:54:11 AM
.code
start:   print "0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99"

Write number, space, write number, space, write number, space,...   . A boring loop done by hand  :skrewy:

hutch--



morgot

Quote from: jj2007 on July 16, 2019, 09:41:03 AM
Yes, Morgot. If it doesn't provide a loop, of course ;-)
Ah, I thought only without a 'loop' operator .. (but with jmp LABEL, cmp.)
Then I don't know how. If without recursion.
Sorry for the bad English