somthing usefull i have found. saves about 50 clock cycles and 2-3 bytes

Started by ninjarider, August 27, 2006, 03:08:45 AM

Previous topic - Next topic

ninjarider


loop:
xor ax, ax
int 16h

stosb

cmp al, 38
je PressUpKey

jmp loop

MoveGraphic:
...some code that moves a graphic around...
ret

PressUpKey
push offset loop
jmp MoveGraphic

I was messing around with my os and i didn't like the coding because there were to much jumping around the code. and i couldn't just jump straight into the routen because there are other parts that call that routen. not sure if this is useful to anyone but it im happy that my thought worked.

my only question about it is how would you push the ip and cs addresses onto the stack to simulate a far call?

zooba

The only problem with this method (which I personally use occasionally, since it can improve some things) is losing some readability and a debugger may not be able to step over the procedure call (probably because it's an unconditional jump, possibly because it doesn't return to where it expects).

IIRC, push cs is valid, but I've no idea how to deal with code in a different segment :wink

Cheers,

Zooba :U

Synfire

Quote from: ninjarider on August 27, 2006, 03:08:45 AMhow would you push the ip
PUSH MACRO ARG:REQ
  IFIDNI ARG, <EIP>
    call $+5
  ELSE
    push ARG
  ENDIF
ENDM


then you can use:

push eip
pop ecx ; ecx now contains the current EIP


This works because CALL pushes the return address onto the stack, then modifies the EIP to point to the new address. In this case $+5 tells it to go to the next instruction.

Regards,
Bryant Keller

ninjarider

Zooba:

yeah i can imagine how a debuger would look at that. have you ever done any programming that look something like this.


loop:
xor ax, ax
int 16h

stosb

cmp al, 38
je PressUpKey
LoopReturnFromUpKey:

jmp loop

MoveGraphic:
...some code that moves a graphic around...
ret

PressUpKey
push offset LoopReturnFromUpKey
jmp MoveGraphic

PBrennick

I do not know about anyone else, but that is a form of obfuscation that I use all the time in proprietory programming.  I never use it in stuff I post here as I want everyone to understand what I am doing.

I like the method very much and have used it for years.  Have you tried to bury the destination and resulting code as data statements and then jump into the middle of the data area that is nested in the code area?  Now that will drive a debugger absolutely nuts !

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Mark_Larson

  What about shuffling things around to get rid of two JMPs



loop:
xor ax, ax
int 16h

stosb

cmp al, 38
jne loop                  ; changed to JNE from JE, and label changed to Loop

; jmp loop              ; removed, saves bytes
push offset loop     ;copied from below
;jmp MoveGraphic     ; removed, falls through now,  saves bytes

MoveGraphic:
...some code that moves a graphic around...
ret


BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

ninjarider

mark_larson:

the code i was using is an example and is not completely what im doing. I would of posted all my code for that. but i think people would get lost in it. the reason im using the jump statements in the loop like that is because i get the keycode and store it to memory then theres a sequence of keys that im checking.
your code has brought an idea to mind that would save more space and i do thank you for that. i think you saved me 8 bytes and 150 clock cylces. which is usefull when doing a boot sector.
question? do you know how to program a bios? and do you have any code i could look at?

PBrennick

Now why would you only ask Mark that type of question.  It is insulting.  Besides, it is a EULA violation to write such code using MASM.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Mark_Larson

Quote from: ninjarider on August 27, 2006, 04:39:06 PM
question? do you know how to program a bios? and do you have any code i could look at?

  I do BIOS programming for a living.  And no I can't provide you with any source code.  I'd get fired, and that'd probably be the least of my worries.  There are plenty of open source BIOS projects you can check out for source code.
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

ninjarider

PBrennick:
sorry for you taking it as an insult. he mentioned about programming bioses and i was just wondering if he was for real.

how hard has it been to program a bios. what language(s) do you use. how would you get a job like that and what kind of degree is required.

PBrennick

Try attending college and learning MicroCode.  Nothing is for free, don't look for a job here.  You will need at least an Associates Degree to be even listened to nowadays, a Bachelors Degree with a specialty to be taken seriously so you are looking at 4 years and big bucks.  Have you tried McDonalds?  Oops, now it is my turn to be insulting, sorry about that, what did you expect?

Look, first you are looking for free code of a restrictive nature and then all of a sudden you want to go to college...

And you expect to be treated seriously, I guess?

...

By the way, it was Mark you were insulting, not me.  He responded well enougth, I think.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

ninjarider

well wither way i  never ment anything offend anyone. yeah i know it takes a college degree to get into stuff like that. i was wondering what kind of degree and if there were any specialties involved. any certain languages that look good to an employeer. maybe i shouldn't of asked for some code. but excuse me for being a little curious as to how it would look.

Mark_Larson

  Just to explain in further detail about why Paul and I were upset.  First, if I gave you any code, I'd be fired on the spot.  Second, I signed a NDA, which means that if I give away the code that opens me to legal problems from my company. Third, I wouldn't be working in BIOS anymore, because no one will want to hire me once they find out why I got fired.  BIOS programmers are an extremely small subset of programmers.  There are maybe 1500 BIOS programmers world wide.  Companies do extensive background checks before hiring someone.  So shoes on the other foot, how would you feel if all that would happen to you if I asked YOU for some code from your company to merely satisfy MY curiousity?

BIOS stuff:
  To have the best chance you should have at least a Bachelor's degree.  I know BIOS programmers without degrees, but it was a LOT harder for them to get hired.  They had to get into Dell at a lower programming group and work their way up.  Second being able to talk directly to the hardware from DOS is example programs is always good.  I had written several programs over the years to talk directly to the hardware.  One was to send an ID command to a hard drive, the other was a game, that talked directly to the video hardware.  So having example programs showing that you know how to write code to access hardware in assembly language.  The BIOS is written in 99% assembly language, and about 1% C.

  After about 3 years of BIOS programming you reach a level in assembly language programming, where it is just as easy to write code in it as it is to write code in C or other HLL.  When that happens programming BIOS isn't any harder than anything else.

  Just as a side note, when I first joined Dell we had two product lines for Desktops, Dimension and Optiplex.  Optiplex had it's motherboard and BIOS designed in house.  Dimension was an Intel motherboard with an Award BIOS.  One time we found a bug with the USB code on a Dimension system.  I did some debugging of the issue because I wrote the USB code for desktops,laptops,and servers.  They sent a guy from Award.  He had a laptop loaded up with his BIOS source code.  He made changes to the BIOS based on what I showed him about the problem.  When he went back to Award my boss asked me if I had seen their source code.  I told him "no".  If I had, I would have been fired on the spot.

  Second side note.  I've seen company source code during interviews.  But in all cases I've always signed an NDA, which means I can't talk about it.

BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm

ninjarider

i didn't think about what i asked. i take it that you two well know each other. besides searching the internet do the two of you or anyone else know any good places for memory maps and stuff. reason for asking is i have been slowly writing my own os and wondering about different areas of the ram. i know it is a good idea if possible to write to the memory location instead of using ints to display stuff a letter at a time.

out of curiosity. i have a dell optiplex laptop. for some reason the bios is saying that it is version a11. i looked on the website and it says the latest is a1. which is better? concidering its a p1 would there be a way to get dma on it?

i had to sign a nda with the last company i was with but that is only in effect in florida and alabama. so i do understand the severity of it.

are either of you in managment position?

Mark_Larson


  Those kinds of questions belong in the Soapbox not the Laboratory.  Please start a topic there :)
BIOS programmers do it fastest, hehe.  ;)

My Optimization webpage
htttp://www.website.masmforum.com/mark/index.htm