Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.os.development > #8295

Re: What form of executable or load module for your OS?

From "Rod Pemberton" <boo@fasdfrewar.cdm>
Newsgroups alt.os.development
Subject Re: What form of executable or load module for your OS?
Date 2015-07-05 02:12 -0400
Organization Aioe.org NNTP Server
Message-ID <op.x1ad7uijyfako5@localhost> (permalink)
References (10 earlier) <mn6vm9$g5a$1@dont-email.me> <fe6d6902-6d1a-4452-94a6-233d89db24e1@googlegroups.com> <mn73e5$3hc$1@dont-email.me> <op.x08ojxp5yfako5@localhost> <853c70d5-5652-42e9-ac0f-e4b832b56ca3@googlegroups.com>

Show all headers | View raw


On Sat, 04 Jul 2015 07:42:20 -0400, Alexei A. Frounze  
<alexfrunews@gmail.com> wrote:
> On Saturday, July 4, 2015 at 1:00:54 AM UTC-7, Rod Pemberton wrote:
>> On Fri, 03 Jul 2015 18:48:56 -0400, James Harris
>> <...@gmail.com> wrote:
>> > "Alexei A. Frounze" <...@gmail.com> wrote in message
>> > news:fe6d6902-6d1a-4452-94a6-233d89db24e1@googlegroups.com...
>> >> On Friday, July 3, 2015 at 2:45:02 PM UTC-7, James Harris wrote:

>> 1) MOVSX
>>
>> MOVSX reg16,r/m8
>>
>> ; where reg8 is low sub-register of reg16
>> MOV reg8,r/m8
>> CBW reg16
>
> CBW, CWD, CDQ and so on don't take an operand. The operand
> is implicit (*AX and *DX).

Yes, I was sleepy ... ;-)

Actually, I didn't think to check CBW for a hardcoded register ...
I do have it listed in my own notes on x86 issues.

So, a longer sequence is needed:

; this needs a register that can be destroyed, e.g., AX
MOV AL,r/m8
CBW
MOV reg16,AX

Alternately, a PUSH/POP wrap to preserve AX:

PUSH AX
... ; code above
POP AX

Or, using NASM's macro functionality (untested):

%macro movsx_ 2
%ifdef I8086
%ifidn %1,ax
   push ax
%endif
   mov al,%2
   cbw
   mov %1,ax
%ifidn %1,ax
   pop ax
%endif
%else
   movsx %1,%2
%endif
%endmacro
%macro mul_ 0
%error "no arguments"
%endmacro

That's based on other macro's I wrote some years ago for
an assembly backend for a simple Forth converter.

You would need to emit "movsx_" with an underscore instead
of "movsx" and include the macro file and optionally define
I8086 or some define to select the non-386 code.  E.g.,

movsx_ bx,cl

If the untested macro is correct, it should emit this
for 386:

movsx bx,cl

And, emit this for 86 (when I8068 is defined) without
preserving AX since it's not a parameter to the movsx_ macro:

mov al,cl
cbw
mov bx,ax

If the first parameter to movsx_ is "ax" it should wrap
with the PUSH/POP of AX.  If not, it needs %ifnidn instead
of %ifidn.

>> 6) NASM auto-generated long branches
>>
>> 6a) use old NASM 0.98.39
>> 6b) set a NASM flag to not do that
>
> What will NASM do then?

Nothing.  The user must fix it.  E.g., perhaps a manual short
branch over jump or an indirect branch.

>> 6c) patch up SmallerC to not generate long branches
>
> There's no such thing as a long branch in Smaller C. If it
> needs a branch, it generates one. The assembler is expected
> to take it from there

Acceptable.

> and do the right thing.

Questionable ...  :-D

If you can design around it being a potential issue, you should.  Yes?

> Smaller C does not attempt to count
> or estimate the size of the resultant machine code and so it has no
> idea of whether any of the generated branches is short or long.
> That's something the assembler must deal with.

Well, NASM has the ability to allow you to specify, e.g.,
'SHORT' and 'NEAR', if the compiler "knows" the branch size.

If not, you can always jump:

Jcc SHORT over
JMP NEAR rel16
over:

NASM has special syntax to allow for re-using short labels.
So, you should be able to do this, if you haven't (unconfirmed):

here:  ; local label needs a prior non-local label
...
Jcc SHORT .over
JMP NEAR rel16
.over
...
Jcc SHORT .over  ; re-used
JMP NEAR rel16
.over


In a similar manner, I have this macro in my code which
conditionally jumps over a call that uses the same label
repeatedly:

%macro xx_ 3
   cmp %1,byte 0
   j%+3 short %%over
   call %2
   %%over
%endmacro

It's used this way for an "if" and "else" (not shown) etc:

%macro if_ 2
   xx_ %1,%2,z
%endmacro

if_ eax,try
...
try:

Note the ability to pass the condition code 'z' from
another macro.

If you aren't using NASM macro's, they're worth a look.
I.e., you could use them to automatically select SHORT,
NEAR, and FAR memory jumps, based on the parameter passed
to the macro, e.g., 's' 'n' 'f' :

%macro jmp_ 2
%ifidn %2,s
   jmp SHORT %1
%elifidn %2,n
   jmp NEAR %1
%elifidn %2,f
   jmp FAR %1
%else
%error "unknown argument"
%endif
%macro jmp_ 0
%error "no arguments"
%endmacro

jmp_ try,s
...
try:

I.e., should be:

jmp SHORT try

HTH, well someone, if not you, you probably read
the NASM manual ...


Rod Pemberton

-- 
Tolerance and socialism attracts intolerance and terrorism.  See:
France, United Kingdom, Germany, Denmark, Belgium, Netherlands, ...

Back to alt.os.development | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-06-25 21:20 -0700
  Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-01 10:36 +0100
    Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-01 21:07 -0700
      Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-02 23:35 -0700
        Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-03 08:35 +0100
          Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-03 02:49 -0700
            Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-03 11:27 +0100
              Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-03 16:54 -0400
                Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-03 22:45 +0100
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-03 17:56 -0400
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-03 15:28 -0700
                Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-03 23:48 +0100
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-03 21:52 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-04 04:00 -0400
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-04 04:42 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-05 02:12 -0400
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-05 00:47 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-05 05:28 -0400
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-05 02:58 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-06 06:21 -0400
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-07 01:44 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-07 05:40 -0400
                Re: What form of executable or load module for your OS? "Kerr Mudd-John" <admin@127.0.0.1> - 2015-07-07 14:02 +0100
                Re: What form of executable or load module for your OS? "wolfgang kern" <nowhere@never.at> - 2015-07-07 18:13 +0200
                Re: What form of executable or load module for your OS? "Kerr Mudd-John" <notsaying@invalid.org> - 2015-07-08 12:54 -0100
                Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-09 13:19 +0100
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-07 22:10 -0700
                Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-08 08:48 +0100
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-08 23:53 -0700
                Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-09 17:29 +0100
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-10 01:01 -0700
                Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-10 13:46 +0100
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-10 00:59 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-08 03:52 -0400
                Re: What form of executable or load module for your OS? "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-08 06:46 -0700
                Re: What form of executable or load module for your OS? "James Harris" <james.harris.1@gmail.com> - 2015-07-09 13:16 +0100
                Re: What form of executable or load module for your OS? "s_dubrovich@yahoo.com" <s_dubrovich@yahoo.com> - 2015-07-11 09:57 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-13 02:47 -0400
                Re: What form of executable or load module for your OS? "s_dubrovich@yahoo.com" <s_dubrovich@yahoo.com> - 2015-07-14 07:39 -0700
                Re: What form of executable or load module for your OS? "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-15 02:37 -0400
        Code insanity "Mike Gonta" <mikegonta@gmail.com> - 2015-07-03 03:47 -0400
          Re: Code insanity "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-03 02:57 -0700
          Re: Code insanity (was: What form of executable or load module for your OS?) "James Harris" <james.harris.1@gmail.com> - 2015-07-03 11:35 +0100

csiph-web