Nested 'for' loop implemented in asm using '.while' loops. :biggrin:
C code implementation: a console program.
#include <stdio.h>
int main() {
int row, col;
for (row = 1; row <= 9; row++) {
for (col = 1; col <= 9; col++) {
printf("r%d", row);
printf("c%d", col);
printf("\n");
}
}
return 0;
}
asm code implementation: assemble and link as console program.
include \masm32\include\masm32rt.inc
.data
row dd 0
col dd 0
.code
start proc
mov row, 0
.while row < 9
inc row
mov col, 0
.while col < 9
inc col
fn crt_printf, "r%d" , row
fn crt_printf, "c%d" , col
fn crt_printf, chr$(13, 10)
.endw
.endw
inkey
exit
start endp
end start
This code might be useful for anyone converting C code to masm compatible assembly.
Both .asm example and .C example :tongue: attached, for comparison.
Isn't uasm supporting for loops ?
#include <stdio.h>
int main(void) {
int row, col;
row = 0;
while (row++ <= 9) {
col = 0;
while (col++ <= 9) {
printf("r:%d c:%d\n", row, col);
}
}
return 0;
}
Always with the C ...
include \masm32\MasmBasic\MasmBasic.inc
Init
For_ row=1 To 9
For_ col=1 To 9
Print Str$("r%i", row), Str$("c%i ", col)
Next
Print
Next
EndOfCode
r1c1 r1c2 r1c3 r1c4 r1c5 r1c6 r1c7 r1c8 r1c9
r2c1 r2c2 r2c3 r2c4 r2c5 r2c6 r2c7 r2c8 r2c9
r3c1 r3c2 r3c3 r3c4 r3c5 r3c6 r3c7 r3c8 r3c9
r4c1 r4c2 r4c3 r4c4 r4c5 r4c6 r4c7 r4c8 r4c9
r5c1 r5c2 r5c3 r5c4 r5c5 r5c6 r5c7 r5c8 r5c9
r6c1 r6c2 r6c3 r6c4 r6c5 r6c6 r6c7 r6c8 r6c9
r7c1 r7c2 r7c3 r7c4 r7c5 r7c6 r7c7 r7c8 r7c9
r8c1 r8c2 r8c3 r8c4 r8c5 r8c6 r8c7 r8c8 r8c9
r9c1 r9c2 r9c3 r9c4 r9c5 r9c6 r9c7 r9c8 r9c9
Purest Assembly :cool:
Why is something so basic in the Workshop?
Quote from: jj2007 on January 18, 2025, 06:44:12 PMPurest Assembly :cool:
If I squint really hard...nope, still can't see any :tongue:
By definition, a source is Assembly if it can be assembled :biggrin:
Computer parts Assembly to computer makes it assembler ?:)
My version
;nested for loops
.data
array 0-3
sqarray 0-3
primearray 0-3
.code
for y=0 to 3
sqrarray[y]=sqr(array[y])
for x=0 ,x<sqrarray[y]
if array[y] mod == 0 primearray[y] =false else primearray[y]=true;break;
end for x
end for y
Quote from: jj2007 on January 18, 2025, 08:25:19 PMBy definition, a source is Assembly if it can be assembled :biggrin:
Like Ikea?
Quote from: sinsi on January 18, 2025, 09:48:34 PMQuote from: jj2007 on January 18, 2025, 08:25:19 PMBy definition, a source is Assembly if it can be assembled :biggrin:
Like Ikea?
Exactly :biggrin:
The only difference is that, unlike Ikea stuff, my sources assemble with MASM ;-)
Thanks guys :badgrin:
Thinking about the code presented, it wouldn't be very hard at all to write a qeditor plugin to do at least this part of a C-->asm conversion. :azn:
The other parts (code within the for loop) will depend... may still need manual tweaks for that bit.
Quote from: zedd151 on January 19, 2025, 01:26:35 AMThinking about the code presented, it wouldn't be very hard at all to write a qeditor plugin to do at least this part of a C-->asm conversion. :azn:
All I can say is rotsa ruck with that.
Quote from: NoCforMe on January 19, 2025, 02:34:10 AMAll I can say is rotsa ruck with that.
Well, thanks man! :thumbsup:
The code has already been started. :cool:
Let me know when you've got it done. And it actually works.
Quote from: zedd151 on January 19, 2025, 02:57:15 AMQuote from: NoCforMe on January 19, 2025, 02:34:10 AMAll I can say is rotsa ruck with that.
Well, thanks man! :thumbsup:
The code has already been started. :cool:
Good luck zedd :thumbsup:
Quote from: daydreamer on January 19, 2025, 09:06:03 PMGood luck zedd :thumbsup:
:smiley: It will take a little while, to get the code 'just right' to enable converting multi-nested for loops. Plus I always get sidetracked (real life, etc.), so never really easy to finish projects that I start.
I call the place where I live "The House of Unfinished Projects".
Quote from: NoCforMe on January 20, 2025, 06:14:16 AMI call the place where I live "The House of Unfinished Projects".
I agree,probably similar home here but in Europe ,but I am looking on the bright side,even unfinished projects going into new area, gui for example makes you more skilled coder while having fun