View Full Version: what does this function really do?

camerahacks >>Applications / Developers >>what does this function really do?


<< Prev | Next >>

zapped- 02-08-2006
what does this function really do?
Has anyone been able to verify that the function that has been commented as a 16 bit multiply (R1:R0 = R5:R4 * R3:R2) is actually exactly that? I have tried running it in the v8 simulator and I am not getting results that make sense to me. When I set R0=$00, R1=$01, R2=$02, R3=$03, R4=$04, R5=$05, shouldn't I get 0xF1608 ($0504 * $0302)? In the simulator, I end up with R0=$00, R1=$02, R2=$00, R3=$04, R4=$04, R5=$05 which I understand means it's result is $0200 The other peculiar thing I notice is that in the firmware right before this function is called, R1 and R0 are almost always set to a value, yet according to R1:R0 = R5:R4 * R3:R2, that would be pointless because R1 and R0 are supposed to be assigned the result of the multiplication. What is wrong here? Is the function incorrectly commented? Is the simulator failing to correctly run the function? or is something else going on here? The function is found at FW_6410_27/bank0 3C1B85DA.03557 and quite a few other places

zapped- 02-09-2006

How about a different function that given input $01 $02 $03 $05 outputs $10 $00 $00 $00, or given input $11 $12 $13 $15 outputs $03 $00 $00 $00, or given input $01 $02 $03 $04 outputs $14 $00 $00 $00 ?????? If you mathamagicians out there can figure it out from those three trial runs without looking at the disassembly, let me know, if not, I can tell you where it is found in the firmware.

BillW- 02-09-2006
Re: what does this function really do?
The other peculiar thing I notice is that in the firmware right before this function is called, R1 and R0 are almost always set to a value, yet according to R1:R0 = R5:R4 * R3:R2, that would be pointless because R1 and R0 are supposed to be assigned the result of the multiplication. I think it's slightly mis-commented. At the beginning of that function it basically does a R4=R0 and R5=R1 followed by a R0=0 and R1=0. So really it appears that it may be R1:R0=R1:R0 * R3:R2 (with R5:R4 playing a temp variable, which gets restored in the end) That doesn't quite explain your odd results in the simulator though.

BillW- 02-09-2006
Re: what does this function really do?
That doesn't quite explain your odd results in the simulator though. Whoops, it does... $100*$302=$30200 ...but the result is 16-bit, so the leading $03 isn't included. That's why you got $200 back.

zapped- 02-09-2006

Thanks BillW that makes sense. On another note, is there a better way to state ;if R4 > $7F then R0=$FF-R0+$01 R1=$FF-R1 R2=$FF-R2 R3=$FF-R3; R4 = R4<<1 That is what I am understanding is happening at 281B1D9F.1B305 in bank8 of 6410 firmware.

BillW- 02-09-2006

1B305 is dead code in my disassembly. Doubtlessly I've missed one of your updates. The best way to restate it would be to find it's overall purpose. As a guess, it looks like some kind of adjustment to implement a negative answer after a 32-bit addition/subtraction result. To comment more I'd need to look at a bit more of the surrounding/calling code and see exactly how R4 is used. Unfortunately I probably won't get around to fixing my disassembly anytime soon, since I'm swamped with personal projects and overdue projects at work.

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.