Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tasm encoding

12 views
Skip to first unread message

Tavis Ormandy

unread,
Feb 22, 2021, 12:34:53 PM2/22/21
to

Hello, I'm trying to convince TASM to generate the sign extending form
of and r16,imm8, something like this:

83 E7 FE and di, 0fffeh

I've tried all ways I can think of writing it (not 1, -2, etc),
but it always generates

81 E7 FE FF and di, 0FFFEh

Using "byte -2" seems to generate incorrect code, but maybe there's a
rationale I don't understand.

I thought perhaps a TASM expert knows a magic incantation or directive to
get the encoding I'm looking for? I'm not really a TASM programmer, I'm
trying to fix an old DOS driver.

Obviously I can just db it in there or use a macro, I'll do that if I
have to, but I think it might get messy.

Tavis.

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger tav...@sdf.org
_\_V _( ) _( ) @taviso

wolfgang kern

unread,
Feb 22, 2021, 11:16:32 PM2/22/21
to
On 22.02.2021 18:34, Tavis Ormandy wrote:
> Hello, I'm trying to convince TASM to generate the sign extending form
> of and r16,imm8, something like this:
>
> 83 E7 FE and di, 0fffeh
>
> I've tried all ways I can think of writing it (not 1, -2, etc),
> but it always generates
>
> 81 E7 FE FF and di, 0FFFEh
>
> Using "byte -2" seems to generate incorrect code, but maybe there's a
> rationale I don't understand.
>
> I thought perhaps a TASM expert knows a magic incantation or directive to
> get the encoding I'm looking for? I'm not really a TASM programmer, I'm
> trying to fix an old DOS driver.
>
> Obviously I can just db it in there or use a macro, I'll do that if I
> have to, but I think it might get messy.

it's several decades ago when I tried TASM, what I still remember is
that "db" was the only option to get desired opcodes.
your example is just one of a lot unsupported code variants in TASM.
__
wolfgang

Tavis Ormandy

unread,
Feb 23, 2021, 12:00:45 AM2/23/21
to
I thought that might be the answer, thanks anyway!

Alexei A. Frounze

unread,
Feb 23, 2021, 3:41:20 AM2/23/21
to
On Monday, February 22, 2021 at 9:34:53 AM UTC-8, Tavis Ormandy wrote:
> Hello, I'm trying to convince TASM to generate the sign extending form
> of and r16,imm8, something like this:
>
> 83 E7 FE and di, 0fffeh
>
> I've tried all ways I can think of writing it (not 1, -2, etc),
> but it always generates
>
> 81 E7 FE FF and di, 0FFFEh
>
> Using "byte -2" seems to generate incorrect code, but maybe there's a
> rationale I don't understand.

TASM 3.2 does it just fine. Here's a listing file I get:
----8<----
Turbo Assembler Version 3.2 02/22/21 10:58:12 Page 1
and.asm



1 ;.8086
2
3 0000 code segment use16
4 assume cs:code
5 org 100h
6
7 0100 start:
8 0100 83 E7 FE and di, 0fffeh
9 0103 83 E7 FE and di, -2
10 0106 83 E7 FF and di, byte -2 ; generates 0ffh instead of 0feh
11
12 0109 code ends
13 end start
...
----8<----

Throwing in .8086 didn't seem to make any effect, even though 083H is an encoding from a newer CPU, the 80386.

The 80286 knows these:
20 /r AND eb,rb 2,mem=7 Logical-AND byte register into EA byte
21 /r AND ew,rw 2,mem=7 Logical-AND word register into EA word
22 /r AND rb,eb 2,mem=7 Logical-AND EA byte into byte register
23 /r AND rw,ew 2,mem=7 Logical-AND EA word into word register
24 db AND AL,db 3 Logical-AND immediate byte into AL
25 dw AND AX,dw 3 Logical-AND immediate word into AX
80 /4 db AND eb,db 3,mem=7 Logical-AND immediate byte into EA byte
81 /4 dw AND ew,dw 3,mem=7 Logical-AND immediate word into EA word

The 80386 knows these:
20 /r AND r/m8,r8 2/7 AND byte register to r/m byte
21 /r AND r/m16,r16 2/7 AND word register to r/m word
21 /r AND r/m32,r32 2/7 AND dword register to r/m dword
22 /r AND r8,r/m8 2/6 AND r/m byte to byte register
23 /r AND r16,r/m16 2/6 AND r/m word to word register
23 /r AND r32,r/m32 2/6 AND r/m dword to dword register
24 ib AND AL,imm8 2 AND immediate byte to AL
25 iw AND AX,imm16 2 AND immediate word to AX
25 id AND EAX,imm32 2 AND immediate dword to EAX
80 /4 ib AND r/m8,imm8 2/7 AND immediate byte to r/m byte
81 /4 iw AND r/m16,imm16 2/7 AND immediate word to r/m word
81 /4 id AND r/m32,imm32 2/7 AND immediate dword to r/m dword
83 /4 ib AND r/m16,imm8 2/7 AND sign-extended immediate byte with r/m word
83 /4 ib AND r/m32,imm8 2/7 AND sign-extended immediate byte with r/m dword

So, either your TASM doesn't know the 80386 encodings or is somehow restricted to produce the pre-80386 ones.
HTH,
Alex

Tavis Ormandy

unread,
Feb 23, 2021, 9:55:03 AM2/23/21
to
On 2021-02-23, Alexei A. Frounze wrote:
>> 81 E7 FE FF and di, 0FFFEh
>>
>> Using "byte -2" seems to generate incorrect code, but maybe there's a
>> rationale I don't understand.
>
> So, either your TASM doesn't know the 80386 encodings or is somehow restricted to produce the pre-80386 ones.

Ah-ha, you're right - it was because I was using the NOSMART directive.

Unfortunately turning that off breaks a different encoding! I'll have to
experiment, hopefully it's an easy fix :)

Thank you.
0 new messages