Pages: 1 ... 3 4 [5] 6
Author Topic: LC/NLS ASM help  (Read 29478 times)
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #60 on: June 10, 2022, 10:30:09 AM »

What is the 81400 ?
Just use any others which written next to your CALLS

I.e

Mov r4, mem
Calls <your routine>
Mov mem, r4 // r4 consist some data which was written before your routine and inspected after so you cannot use it here
Mov r6, mem // r6 written here so it wont consist any useful data, use it

Another way is to use system stack
81400 forget it, I yust put that number I mean some free RAM space

How can I be sure that r6 is not used somewere else. Let say 60 program code lines before my call.
Or I need to watch only that subroutine?

Maybe best that I put example what I mean
Logged
fknbrkn
Hero Member
*****

Karma: +177/-18
Offline Offline

Posts: 1405


mk4 1.8T AUM


« Reply #61 on: June 10, 2022, 01:43:19 PM »

Again
Registers are global ! That means if r6 was written in main thread, it stores same data when cpu jumps to your subroutine, do rhings in it and rets back. So just avoid using registers which first instruction after your custom call are reading from register and feel free if its write to register
Its just a simple logic idk how to say
Logged
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #62 on: June 10, 2022, 03:15:42 PM »

Again
Registers are global ! That means if r6 was written in main thread, it stores same data when cpu jumps to your subroutine, do rhings in it and rets back. So just avoid using registers which first instruction after your custom call are reading from register and feel free if its write to register
Its just a simple logic idk how to say
I understand they are global

And this is all I need to hear, I was assume that but only need confirmation
Thank you
Logged
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #63 on: July 09, 2022, 11:28:21 AM »

Is this okay?

So this is how original look like



I set here call function



In my function I check 386000( my flag) to set zwgru to -30 or to not touch it all (leave at it is)



After that I put this thing two things like was original (still don't know what this [r0+] mean )


After some rest I will check if I forget something in code or if something is wrong .

Only question I want to know did I made jump and return from and to original function?

Don't have car here to test it


Logged
fknbrkn
Hero Member
*****

Karma: +177/-18
Offline Offline

Posts: 1405


mk4 1.8T AUM


« Reply #64 on: July 09, 2022, 01:56:26 PM »

Its ok
But why are you not hooking at the loc_8B89B2 ? All others are obviously min/max caps so just replacing movb zwgru, rl4 would be a bit easier imo, just remember that r4 consists original zwgru value and dont touch it in your routine, just use r5 instead

cmpb rl4, #0 are unecessary. Z flag triggered even at movb operation
Logged
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #65 on: July 09, 2022, 02:33:46 PM »

Its ok
But why are you not hooking at the loc_8B89B2 ? All others are obviously min/max caps so just replacing movb zwgru, rl4 would be a bit easier imo, just remember that r4 consists original zwgru value and dont touch it in your routine, just use r5 instead

cmpb rl4, #0 are unecessary. Z flag triggered even at movb operation
I am still exploring how all this works. I know I can do that way, but I want to find more ways so I can understand it better.


RL4 or R4?  I know that RL4 is low byte of R4, so touching RL4 will change value of R4.  But general speaking zwgru is uint_8 value?
If after:  movb  zwgru, rl4
...
XXXX
...
I have DB 00 (like in this case)   does that mean, that in most case rl4 value is no longer needed(it will be most likely overwriten in some next function) so I am free to use it XXXX area



Tnx for shortcout about Z flag and all other help
« Last Edit: July 09, 2022, 02:37:45 PM by BlackT » Logged
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #66 on: July 12, 2022, 04:51:24 PM »

This look nicer


I take a look and didn't find that FDDA is used anywhere in code. So I will use it to set my flags
Logged
fknbrkn
Hero Member
*****

Karma: +177/-18
Offline Offline

Posts: 1405


mk4 1.8T AUM


« Reply #67 on: July 15, 2022, 06:03:49 AM »

; conditions
exts   #38h, #1
movb   rl5, LC_flag
jmpr    cc_z, loc_end
;eof

;params conditions

loc_cut:
exts   #8Ah, #1
movb   rl4, LC_zwgru

loc_end:
movb    zwgru, rl4
rets

Quote
RL4 or R4?  I know that RL4 is low byte of R4, so touching RL4 will change value of R4.
This is code of my LC, called from  loc_8B89B2 (in your case).
new fucntion called in place where rl4 moved to zwgru. so rl4 contain zwgru value and you want to touch it in your routine, rl5 used for conditional checks
Quote
But general speaking zwgru is uint_8 value?
8bytes signed int8_t

Quote
If after:  movb  zwgru, rl4
...
XXXX
...
I have DB 00 (like in this case)   does that mean, that in most case rl4 value is no longer needed(it will be most likely overwriten in some next function) so I am free to use it XXXX area

absolutely no. check how map calculations are done. in most cases they writes calculated value into r4 and rets to main code
general rule here - look at the main code flow after your routine (even after rets) if you see some register reading first, then you cannot use it. just imagine this situation

mov r5, rl_w
mov r4, plsol_w
shr r4, #8
movb plsol, rl4
mov rlkh_w, r5
mov r7, rkat_w

and you change it to

mov r5, rl_w
mov r4, plsol_w
shr r4, #8
calls #8Ah, myRoutine ; < r4 contain plsol value!
mov rlkh_w, r5 ;  r5 goes through your routine, do not use it!
mov r7, rkat_w ; r7 only written here, so in your routine its not contain any useful data, could be used

<myRoutine:>

mov r4, nmot_w ; < and now you changed it to nmot_w
cmp r4, myNmotLimit
jmpr cc_ule, loc_end
....
loc_end:
movb plsol, rl4 ;< feeding plsol with part of nmot (bad idea)
rets

as of the last screen - this wont work
you overwrite zwgru with stock value anyway


Logged
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #68 on: July 17, 2022, 02:08:27 AM »

Yes you are right, ah that speed and tired head...
In attachment is correction( I made this cpr twice beacuse I still don't know how to put NOP I play safe before I get everything sorted in head)

About those registers this was my first idea

start of my function:

mov word_386000, r4
mov word_386002, r5
mov word_386004, r6

... programing with r4,r5,r6 in my function(without touching address 386000-4)...

mov r4, word_386000
mov r5, word_386002
mov r6, word_386004
rets


So store registers in some unused space to save them, like a safe copy.  Than before exit of function pull values from safe copy to that registers
Logged
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #69 on: February 28, 2023, 03:44:51 PM »

I assume this is not possible but can I make call function after I already make call


Working example:
at 8A000   I make Call 8E540
At 8E540 my function
....
...
Rets (this will return to 8A004)

But If I make something like this

at 8A000   I make Call 8E540
At 8E540 my function
....
Call 8E640
Rets

At 8E640 my function#2
....
Rets  

this will return to next array where I called 8E640, but after that I will again have rets. Will after that rets send to 8A004?
Logged
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #70 on: March 01, 2023, 04:28:03 AM »

To make better visual what I want to achieve
So I have good well known call before tsrldyn


After that call again in my function I have call to another sub ( take close look at bottom left)



And that called sub again have rets

Logged
prj
Hero Member
*****

Karma: +919/-429
Offline Offline

Posts: 5860


« Reply #71 on: March 01, 2023, 04:42:01 AM »

Reading the user manual helps.
Every time a call is made the PC is pushed onto the stack and popped off with RET.
In case of CALLS also the segment is pushed onto the stack and then both the segment and the address get popped off.
As long as you don't exceed the stack size you can chain as many calls as you like, obviously the amount of calls and returns has to be balanced.

If you are patching an already existing call, you can also just jump to the original call location after you're done with your code.
This is becomes a lot more important on TriCore where calls automagically save and restore a bunch of registers.
« Last Edit: March 01, 2023, 04:44:03 AM by prj » Logged

PM's will not be answered, so don't even try.
Log your car properly.
BlackT
Hero Member
*****

Karma: +79/-39
Offline Offline

Posts: 1423



« Reply #72 on: March 01, 2023, 05:04:48 AM »

Thank you, I will work with JMPS from now on.
Logged
fknbrkn
Hero Member
*****

Karma: +177/-18
Offline Offline

Posts: 1405


mk4 1.8T AUM


« Reply #73 on: March 01, 2023, 09:08:15 AM »

You can safely use few calls
Personally ive never faced with stack overflow with 1-2 incapsulated calls and map calculation (vars pushed in stack)
Logged
prj
Hero Member
*****

Karma: +919/-429
Offline Offline

Posts: 5860


« Reply #74 on: March 01, 2023, 11:07:19 AM »

Thank you, I will work with JMPS from now on.
On C16x no need, you can just spam calls.
But hey, if you ever move to TriCore it's good to not make it a habit.

But then again, if you just want to execute some code and then go to the original routine, then you can also just use JMPS, it makes no practical difference.
Logged

PM's will not be answered, so don't even try.
Log your car properly.
Pages: 1 ... 3 4 [5] 6
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Page created in 0.022 seconds with 16 queries. (Pretty URLs adds 0s, 0q)