Jump to content

Why Doesn't This Code Work?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I made this code that is supposed to scan through ISO9660 directory records. Those are in memory, at the time of execution. The code should compare the requested filename to the filename in the directory record, and if they're not the same, then it's supposed to go on to the next record. The problem is that it doesn't go on to the next record, even though the code looks to me like it should.

'[ebp-8]' is the memory address of the end of the directory, and it's used here to check if the loop needs to stop yet.

lp1: 

		mov eax, dword ptr [ebp-08] 

		cmp ebx, eax 

		jnl lp1s 

		

		mov edx, ebx 

		add ebx, 33 

		mov eax, dword ptr [ebp+12] 

		call strcmp 

		cmp eax, 0 

		jz lp1s 

		

		mov ebx, edx 

		xor eax, eax 

		xor edx, edx 

		mov al, byte ptr [ebx] 

		add ebx, eax 

		jmp lp1 

	lp1s: 

And the other thing that I'm kind of confused about is: does there have to be an even number of directory records per sector? (If yes, then what's used for padding, until the next sector?)

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
I figured out what the problem was.

Part of the problem was that my code wasn't checking to see if it reached a 0-sized directory record; because of that, my program was getting stuck in an endless loop, because the rest of the 2048 bytes were 0's.

The other part of the problem was my strcmp() function; I forgot the 'inc edx' in the character-comparing loop (what a silly mistake). Here's that loop with the 'inc edx':
	xor eax, eax 

	lp1: 

		mov al, byte ptr [ebx] 

		cmp al, 0 

		jz lp1s 

		sub al, byte ptr [edx] 

		jnz lp1s 

		

		inc ebx 

		inc edx 

		jmp lp1 

	lp1s: 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users