I want to place the solutions for the following code, each answer and store them into an array.
1+2=3
3->array
4+2=6
6->array
3+3=6
6->array
total 4s = 1
total 6s = 2
etc????
TITLE Random
INCLUDE Irvine32.inc
RandLoop PROTO :DWORD,:DWORD
RandLoop2 PROTO :DWORD,:DWORD,:DWORD
;#########################################################
COUNT = 10
COUNT2 = 2
;#########################################################
.DATA
commaStr BYTE ", ",0
str1 BYTE "Total= ",0
;#########################################################
.CODE
RandLoop2 PROC dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
;this procedure show X columns of random value betwen dwMinVal and dwMaxVal
;this procedure add one colum to show the sum of values
LOCAL dwRange2:DWORD
LOCAL VALUE_FINAL:DWORD
mov VALUE_FINAL,0 ;we initialize this variable with zero
;cmp COLUMN,0 ;zero columns?
;mov COUNT2,0 ;set count2 to zero
JE DO_NOTHING ;so do nothing
mov eax,dwMaxVal2
sub eax,dwMinVal2
mov dwRange2,eax
mov edx,OFFSET commaStr
; mov ecx,COLUMN
mov ecx,COUNT2
RLoop1:
mov eax,dwRange2
call RandomRange
add eax,dwMinVal2
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
call WriteInt
call WriteString
; call DumpRegs
loop RLoop1
mov edx, offset str1 ;we show the "total= "
call WriteString
mov eax,VALUE_FINAL ;and after we show the sum of the numbers
call WriteInt
call Crlf ;an enter in the end of column
DO_NOTHING:
ret
RandLoop2 ENDP
main PROC
call Clrscr
call Randomize ;initialize random generator
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
call Crlf
exit
main ENDP
;#########################################################
END main
OR
Would it make more sense to put each value into a different stack?
Is this possible?
2+5=7
7->[7_stack]
4+2=6
6->[6_stack]
1+6=7
7->[7_stack]
6_stack=1
7_stack=4
Which is faster or better or possible?
it depends on how you are going to use the information, really
the stack is generally used for temporary values with "local" scope
an array created in one of the data sections is more permanent and has "global" scope
the scope refers to how it may be accessed
local scope means that only the routine where the locals are defined can access the data
global scope means the data can be accessed by any part of the program
sounds to me like you may want a global array
.DATA?
MyArray db 100 dup(?) ;creates an empty array of 100 bytes
.DATA
AryPtr dd MyArray ;a dword value that tells you the current position in the array
to use it, move AryPtr into a register
that register may then be used to add items
this example shows how to store a byte
mov edx,AryPtr
;
;
mov [edx],al ;store AL into the array
inc edx ;point to next byte
when you are done updating the array, store the pointer so you know where you left off
mov AryPtr,edx
now, AryPtr tells you where the next byte goes
Have a look at the stosd opcode, really cute for that purpose.
stosd opcode?
when can I get a link?
I am getting some really disgusting hearts and smiley faces in my output....??
TITLE Random
INCLUDE Irvine32.inc
RandLoop PROTO :DWORD,:DWORD
RandLoop2 PROTO :DWORD,:DWORD,:DWORD
;#########################################################
COUNT = 10
COUNT2 = 2
;#########################################################
.DATA?
MyArray db 100 dup(?) ;creates an empty array of 100 bytes
.DATA
AryPtr dd MyArray ;a dword value that tells you the current position in the array
commaStr BYTE ", ",0
str1 BYTE "Total= ",0
;#########################################################
.CODE
RandLoop2 PROC dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
;this procedure show X columns of random value betwen dwMinVal and dwMaxVal
;this procedure add one colum to show the sum of values
LOCAL dwRange2:DWORD
LOCAL VALUE_FINAL:DWORD
mov VALUE_FINAL,0 ;we initialize this variable with zero
;cmp COLUMN,0 ;zero columns?
;mov COUNT2,0 ;set count2 to zero
JE DO_NOTHING ;so do nothing
mov eax,dwMaxVal2
sub eax,dwMinVal2
mov dwRange2,eax
mov edx,OFFSET commaStr
; mov ecx,COLUMN
mov ecx,COUNT2
RLoop1:
mov edx,AryPtr
mov eax,dwRange2
call RandomRange
add eax,dwMinVal2
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
call WriteInt
call WriteString
loop RLoop1
mov edx, offset str1 ;we show the "total= "
call WriteString
mov eax,VALUE_FINAL ;and after we show the sum of the numbers
call WriteInt
add [VALUE_FINAL],edx
mov [edx],al ;store AL into the array
inc edx ;point to next byte
; call DumpRegs
call Crlf ;an enter in the end of column
DO_NOTHING:
ret
RandLoop2 ENDP
main PROC
call Clrscr
call Randomize ;initialize random generator
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
call Crlf
exit
main ENDP
Hmmmm.
I tried using esi since I did a dumpregs and saw edx in use.
I also tried to put the array increment into a separate procedure. That did nothing to help except make debugging easier.
Granted, I already knew what was jacked up. :P
:)
some kind of wild buffer error.
Love the site, finally making real progress!
:)
***********************more noobie code********************
TITLE Random
INCLUDE Irvine32.inc
RandLoop PROTO :DWORD,:DWORD
RandLoop2 PROTO :DWORD,:DWORD,:DWORD
;#########################################################
COUNT = 10
COUNT2 = 2
;#########################################################
.DATA?
MyArray db 100 dup(?) ;creates an empty array of 100 bytes
.DATA
AryPtr dd MyArray ;a dword value that tells you the current position in the array
commaStr BYTE ", ",0
str1 BYTE "Total= ",0
;#########################################################
.CODE
RandLoop2 PROC dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
;this procedure show X columns of random value betwen dwMinVal and dwMaxVal
;this procedure add one colum to show the sum of values
LOCAL dwRange2:DWORD
LOCAL VALUE_FINAL:DWORD
mov VALUE_FINAL,0 ;we initialize this variable with zero
;cmp COLUMN,0 ;zero columns?
;mov COUNT2,0 ;set count2 to zero
mov esi,AryPtr
JE DO_NOTHING ;so do nothing
mov eax,dwMaxVal2
sub eax,dwMinVal2
mov dwRange2,eax
mov edx,OFFSET commaStr
; mov ecx,COLUMN
mov ecx,COUNT2
RLoop1:
mov eax,dwRange2
call RandomRange
add eax,dwMinVal2
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
call WriteInt
call WriteString
loop RLoop1
mov edx, offset str1 ;we show the "total= "
call WriteString
mov eax,VALUE_FINAL ;and after we show the sum of the numbers
call WriteInt
add [VALUE_FINAL],edx
call array1
call DumpRegs
call Crlf ;an enter in the end of column
DO_NOTHING:
ret
RandLoop2 ENDP
array1 PROC
mov [esi],al ;store AL into the array
inc esi ;point to next byte
array1 ENDP
main PROC
call Clrscr
call Randomize ;initialize random generator
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
call Crlf
exit
main ENDP
;#########################################################
END main
array1 PROC
mov [esi],al ;store AL into the array
inc esi ;point to next byte
array1 ENDP
you must end array1 proc with RET ok ?
array1 PROC
mov [esi],al ;store AL into the array
inc esi ;point to next byte
ret
array1 ENDP
Quote from: bcddd214 on April 24, 2011, 05:07:50 PM
stosd opcode?
when can I get a link?
Here is your link: \masm32\help\opcodes.chm
Fascinating lecture, by the way :green2
Lecture?
What, my gross attempt to move from pathetic noob to a simple idiot?
:P
I am trying!
Quote from: bcddd214 on April 24, 2011, 06:09:27 PM
I am trying!
It seems you want to save VALUE_FINAL into that array and not AL byte
Yes or no ?
Every time you INVOKE RandLoop2 you want to save that VALUE_FINAL
Yes or no ?
i thought i gave you a link to Randy Hyde's AoA online
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html
chapter 6 has most of the instructions
the string instructions, like STOSD, are covered in chapter 15
Quote from: RuiLoureiro on April 24, 2011, 06:12:28 PM
Quote from: bcddd214 on April 24, 2011, 06:09:27 PM
I am trying!
It seems you want to save VALUE_FINAL into that array and not AL byte
Yes or no ?
Every time you INVOKE RandLoop2 you want to save that VALUE_FINAL
Yes or no ?
YES
YES
3+5=8
8->array1
2+3=5
5->array
show array
so, you want to create a DWORD array - not a BYTE array
make it big enough so you don't overflow
a good idea to check to see if it's full, but it's easier to make a bigger buffer - lol
if you put the value you want to store in EAX, and the current buffer pointer in EDI, then use STOSD,
it will store the value in the array
after that, store the new pointer from EDI
.DATA?
MyArray dd 100 dup(?) ;creates an empty array of 100 dwords
.DATA
AryPtr dd MyArray ;a dword value that tells you the current position in the array
;
;
;
mov eax,ValueToStore
mov edi,AryPtr
stosd
mov AryPtr,edi
with the STOSD instruction, EDI is automatically updated to point to the next dword - just store it
if your function stores 3 dwords into the array, you only need to load edi with the pointer once at the beginning of the routine
then store it back to AryPtr at the end...
mov edi,AryPtr
;
;
stosd
;
;
stosd
;
;
stosd
;
;
mov AryPtr,edi
Another solution
.DATA
Index dd 0 ; define this Index
VALUE_FINAL dd 0
Replace this:
.DATA?
MyArray db 100 dup(?) ;creates an empty array of 100 bytes
by this:
.DATA?
MyArray dd 100 dup(?) ;creates an empty array of 100 dwords
AND
array1 PROC
mov ebx, Index
mov eax, VALUE_FINAL
mov [esi+ebx], eax ;store EAX into the array
add ebx, 4 ;point to next dword
mov Index, ebx
ret
array1 ENDP
ShowArray proc
xor ebx, ebx
_next: cmp ebx, Index
jne @F
ret
;
@@: mov eax, [esi+ebx] ; get EAX from the array
add ebx, 4 ; point to next dword
; »»»»»»»»»»»»»
; print it HERE
; »»»»»»»»»»»»»
jmp _next
ShowArray endp
The first thing it barks at is undefined symbol of FINAL_VALUE and INDEX
I figure out that FINAL_VALUE is defined in the RandLoop PROC and can't reach the reach it in the subroutine.
Do I simply set FINAL_VALUE right under .code to be global and put index there too?
Quote from: bcddd214 on April 24, 2011, 07:00:02 PM
The first thing it barks at is undefined symbol of FINAL_VALUE and INDEX
I figure out that FINAL_VALUE is defined in the RandLoop PROC and can't reach the reach it in the subroutine.
Do I simply set FINAL_VALUE right under .code to be global and put index there too?
yes, but under .DATA
.DATA
Index dd 0 ; define this Index
VALUE_FINAL dd 0
or - return it from the routine in EAX
then, store it
Another way:
array1 PROC
mov ebx, Index
;mov eax, VALUE_FINAL
mov [esi+ebx], eax ;store EAX into the array
add ebx, 4 ;point to next dword
mov Index, ebx
ret
array1 ENDP
and
mov eax, VALUE_FINAL
call array1
;.....................
ShowArray proc
xor ebx, ebx
_next: cmp ebx, Index
jne @F
ret
;
@@: mov eax, [esi+ebx] ; get EAX from the array
add ebx, 4 ; point to next dword
; »»»»»»»»»»»»»
; print it HERE
; »»»»»»»»»»»»»
jmp _next
ShowArray endp
This method does not error, but also does not show the array??
Trying the other way now.
TITLE Random
INCLUDE Irvine32.inc
RandLoop PROTO :DWORD,:DWORD
RandLoop2 PROTO :DWORD,:DWORD,:DWORD
;#########################################################
COUNT = 10
COUNT2 = 2
;#########################################################
.DATA?
MyArray db 100 dup(?) ;creates an empty array of 100 bytes
.DATA
AryPtr dd MyArray ;a dword value that tells you the current position in the array
commaStr BYTE ", ",0
str1 BYTE "Total= ",0
Index dd 0 ; define this Index
VALUE_FINAL dd 0
;#########################################################
.CODE
RandLoop2 PROC dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
;this procedure show X columns of random value betwen dwMinVal and dwMaxVal
;this procedure add one colum to show the sum of values
LOCAL dwRange2:DWORD
;LOCAL VALUE_FINAL:DWORD
mov VALUE_FINAL,0 ;we initialize this variable with zero
;cmp COLUMN,0 ;zero columns?
;mov COUNT2,0 ;set count2 to zero
mov esi,AryPtr
JE DO_NOTHING ;so do nothing
mov eax,dwMaxVal2
sub eax,dwMinVal2
mov dwRange2,eax
mov edx,OFFSET commaStr
; mov ecx,COLUMN
mov ecx,COUNT2
RLoop1:
mov eax,dwRange2
call RandomRange
add eax,dwMinVal2
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
call WriteInt
call WriteString
loop RLoop1
mov edx, offset str1 ;we show the "total= "
call WriteString
mov eax,VALUE_FINAL ;and after we show the sum of the numbers
call WriteInt
add [VALUE_FINAL],edx
call array1
; call DumpRegs
call Crlf ;an enter in the end of column
DO_NOTHING:
ret
RandLoop2 ENDP
array1 PROC
mov ebx, Index
mov eax, VALUE_FINAL
mov [esi+ebx], eax ;store EAX into the array
add ebx, 4 ;point to next dword
mov Index, ebx
ret
array1 ENDP
ShowArray proc
xor ebx, ebx
_next: cmp ebx, Index
jne @F
ret
;
@@: mov eax, [esi+ebx] ; get EAX from the array
add ebx, 4 ; point to next dword
; »»»»»»»»»»»»»
; print it HERE
; »»»»»»»»»»»»»
jmp _next
ShowArray endp
main PROC
call Clrscr
call Randomize ;initialize random generator
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
call Crlf
; call DumpRegs
exit
main ENDP
;#########################################################
END main
First:
ShowArray proc
xor ebx, ebx
_next: cmp ebx, Index
jne @F
ret
;
@@: mov eax, [esi+ebx] ; get EAX from the array
add ebx, 4 ; point to next dword
; »»»»»»»»»»»»»
; print it HERE
; »»»»»»»»»»»»»
call WriteInt ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
jmp _next
ShowArray endp
Second:
main PROC
call Clrscr
call Randomize ;initialize random generator
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
call Crlf
call ShowArray ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; call DumpRegs
exit
main ENDP
It seems there is an error HERE:
Why to add EDX to VALUE_FINAL ????????
mov edx, offset str1 ;we show the "total= "
call WriteString
mov eax,VALUE_FINAL
call WriteInt
;add [VALUE_FINAL],edx <<<<<<<<<<<<<<Remove this line
call array1
; call DumpRegs
call Crlf
You need to do this (or NOT if VALUE_FINAL is global ):
mov eax, VALUE_FINAL
call array1
WORKS!
Now I just need to figure out why.
I have never seen that method of displaying an array.
Any chance you could break it down for me?
*****************************output**********************
+1, +3, Total= +4
+3, +3, Total= +6
+1, +3, Total= +4
+1, +1, Total= +2
+2, +1, Total= +3
+2, +3, Total= +5
+4, +5, Total= +9
+2, +3, Total= +5
+3, +5, Total= +8
+2, +1, Total= +3
+4+6+4+2+3+5+9+5+8+3
EAX=00000003 EBX=00000028 ECX=00000000 EDX=00405007
ESI=00405A1C EDI=00000000 EBP=0012FF94 ESP=0012FF8C
EIP=00401151 EFL=00000246 CF=0 SF=0 ZF=1 OF=0
***********************code****************************
TITLE Random
INCLUDE Irvine32.inc
RandLoop PROTO :DWORD,:DWORD
RandLoop2 PROTO :DWORD,:DWORD,:DWORD
;#########################################################
COUNT = 10
COUNT2 = 2
;#########################################################
.DATA?
MyArray dd 100 dup(?) ;creates an empty array of 100 bytes
.DATA
AryPtr dd MyArray ;a dword value that tells you the current position in the array
commaStr BYTE ", ",0
str1 BYTE "Total= ",0
Index dd 0 ; define this Index
VALUE_FINAL dd 0
;#########################################################
.CODE
RandLoop2 PROC dwMinVal2:DWORD,dwMaxVal2:DWORD,COLUMN:DWORD
;this procedure show X columns of random value betwen dwMinVal and dwMaxVal
;this procedure add one colum to show the sum of values
LOCAL dwRange2:DWORD
;LOCAL VALUE_FINAL:DWORD
mov VALUE_FINAL,0 ;we initialize this variable with zero
;cmp COLUMN,0 ;zero columns?
;mov COUNT2,0 ;set count2 to zero
mov esi,AryPtr
JE DO_NOTHING ;so do nothing
mov eax,dwMaxVal2
sub eax,dwMinVal2
mov dwRange2,eax
mov edx,OFFSET commaStr
; mov ecx,COLUMN
mov ecx,COUNT2
RLoop1:
mov eax,dwRange2
call RandomRange
add eax,dwMinVal2
add [VALUE_FINAL],eax ;first moment the value_final is zero, second moment is ????????
call WriteInt
call WriteString
loop RLoop1
mov edx, offset str1 ;we show the "total= "
call WriteString
mov eax,VALUE_FINAL ;and after we show the sum of the numbers
call WriteInt
call array1
; call DumpRegs
call Crlf ;an enter in the end of column
DO_NOTHING:
ret
RandLoop2 ENDP
array1 PROC
mov ebx, Index
mov eax, VALUE_FINAL
mov [esi+ebx], eax ;store EAX into the array
add ebx, 4 ;point to next dword
mov Index, ebx
ret
array1 ENDP
ShowArray proc
xor ebx, ebx
_next: cmp ebx, Index
jne @F
ret
;
@@: mov eax, [esi+ebx] ; get EAX from the array
add ebx, 4 ; point to next dword
; »»»»»»»»»»»»»
; print it HERE
; »»»»»»»»»»»»»
call WriteInt
jmp _next
ShowArray endp
main PROC
call Clrscr
call Randomize ;initialize random generator
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
INVOKE RandLoop2,1,6,0
call Crlf
call ShowArray
call DumpRegs
exit
main ENDP
;#########################################################
END main
«I have never seen that method of displaying an array»
+4+6+4+2+3+5+9+5+8+3
Try this:
ShowArray proc
xor ebx, ebx
_next: cmp ebx, Index
jne @F
ret
;
@@: mov eax, [esi+ebx] ; get EAX from the array
add ebx, 4 ; point to next dword
; »»»»»»»»»»»»»
; print it HERE
; »»»»»»»»»»»»»
call WriteInt ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
call Crlf
jmp _next
ShowArray endp
That's what I have my friend!
And she works great.
If I wanted to access this array and see how many of what digits are in that array, I would use TYPEDEF?
«If I wanted to access this array and see how many of what digits are in that array,
I would use TYPEDEF?»
No, the number of digits in that array is in Index. Divide it by 4.
If Index=16 then the number is equal 4
If you want to show
mov eax, Index
shr eax, 2 ; divide by 4
call WriteInt ; show number of digits in the array
I will start a new topic on this.
It is similar, but different enough that others might want it separate.