1 Replies - 1275 Views - Last Post: 02 June 2012 - 07:47 AM

#1 muhteremmuho  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 164
  • Joined: 06-January 11

Assembly matrix

Posted 02 June 2012 - 04:28 AM

Hi all.I need your help.I want to write 'game of life's code.I started,but I cant continue.I make 12x12 matrix but I dont want to insert x first rox,last row,first column and last colum.I dont insert first and last row but I dont want to insert 1st and last column.please look at code.and I must write cmp eax,83,95,107... but I take error because I exceed 5 byte :S ?I tried 'or' but no solution. If you have assembly code of 'game of life'please contact me
TITLE GameofLife              (po.asm)

INCLUDE Irvine32.inc
COUNT = 144

.data
x BYTE "X"
array DWORD COUNT DUP(?)
randVal DWORD ?

.code

main PROC

    call Randomize
   
	mov ecx,20
	mov esi,OFFSET array
    mov edi,esi
	mov ebx,type array
L1:
    mov eax,120
    mov edx,0
	call Randomrange
	add  eax,12
	
	cmp eax,12
	je rndm
	cmp eax,24
	je rndm
	cmp eax,36
	je rndm
	cmp eax,48
	je rndm
	cmp eax,60
	je rndm
	cmp eax,72
	je rndm
	cmp eax,84
	je rndm
	cmp eax,96
	je rndm
	cmp eax,108
	je rndm
	cmp eax,120
	je rndm
    cmp eax,23
	je rndm
	cmp eax,35
	je rndm
	cmp eax,47
	je rndm
	cmp eax,59
	je rndm
	cmp eax,71
	je rndm
	jne nrndm
	rndm: 
	mov eax,120
	call Randomrange
	add  eax,12
	nrndm:
    mul ebx
	mov esi,edi
	add  esi,eax
	mov edx,OFFSET x
	mov [esi],edx          ; store in array	
	loop L1
	call Crlf
	
    mov ecx,12

	L3:
	mov ebx,ecx
	mov ecx,12
	
	L2:	mov edx,[edi]  ;get integer from array
	cmp edx,0
    je zero	
	jne xxx
	zero:mov eax,edx
	call writedec
	jmp non
	xxx:call writestring
	non:
	add  edi,TYPE array	  ;next array position	
	loop L2
	
	call crlf
	mov ecx,ebx
	loop L3
	
	exit
main ENDP
END main


Is This A Good Question/Topic? 0
  • +

Replies To: Assembly matrix

#2 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,281
  • Joined: 28-March 11

Re: Assembly matrix

Posted 02 June 2012 - 07:47 AM

What version of MASM and Irvine are you using? You should be getting errors left and right with that code.

Make this the first line of your source:
option casemap :none 
Why? Kip wrote a function called Crlf, which you use in your code BUT you also use/call crlf. Technically they ARE NOT THE SAME. By using option casemap :none, the Assembler would of caught that and told you about it. Why should you do that? It will help cut down on bugs tremendously.

Assembly is hard enough to read, why not use descriptive label names instead of L1, L2, etc? Also since you are using a letter and number for label names, why would you put L3 BEFORE L2?

For code readability, don't put instructions on the same line as labels. Also, use some kind of indentation.

Don't do this:
add edi,TYPE array
instead, use the array size:
add edi, 4
This way you don't have to go back through all the lines of code to find out what kind of array it is - byte,word,dword etc.. it is a bit more self documenting. Even better use an equate:

ARRAY_DWORD     equ     4
ARRAY_BYTE      equ     1
ARRAY_WORD      equ     2

So your code would become:
add edi, ARRAY_DWORD
a bit more understandable as to what is going on.

Now isn't this a bit more readable:
L3:
    mov     ebx, ecx
    mov     ecx, 12

L2:	
    mov     edx, [edi]  ;get integer from array
    cmp     edx, 0
    je      zero	
    jne     xxx
    
zero:
    mov     eax, edx
    call    WriteDec
    jmp     non
    
xxx:
    call    WriteString
    
non:
    add     edi, ARRAY_DWORD	  ;next array position	
    loop    L2


Quote

but I dont want to insert x first rox,last row,first column and last colum.I dont insert first and last row but I dont want to insert 1st and last column
What does that mean? Can you explain that a bit more?

Quote

but I dont want to insert x first rox,last row,first column and last colum.I dont insert first and last row but I dont want to insert 1st and last column

What errors and on what line? Post the exact error messages as the Assembler/Linker give you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1