Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

HEAD CRASH!! FILES LOST!! Details at 11.


programming / alt.lang.asm / Re: How to read a byte?

SubjectAuthor
* How to read a byte?Mateusz Viste
`* Re: How to read a byte?Robert Wessel
 `- Re: How to read a byte?Mateusz Viste

1
Subject: How to read a byte?
From: Mateusz Viste
Newsgroups: alt.lang.asm
Organization: Guest of ProXad - France
Date: Thu, 19 Sep 2019 21:34 UTC
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!cleanfeed2-b.proxad.net!nnrp1-1.free.fr!not-for-mail
From: mate...@wont.tell (Mateusz Viste)
Subject: How to read a byte?
Newsgroups: alt.lang.asm
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Date: 19 Sep 2019 21:34:16 GMT
Lines: 27
Message-ID: <5d83f458$0$3523$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 19 Sep 2019 23:34:16 CEST
NNTP-Posting-Host: 82.64.0.151
X-Trace: 1568928856 news-3.free.fr 3523 82.64.0.151:55978
X-Complaints-To: abuse@proxad.net
View all headers
Here I am, trying to read the lowest 8 bits of the RTC timer on an 8086
PC. Assembly is not something I am comfortable with, hence the question
might be stupid (and certainly light years behind usual topics on this
group). Please bear with me.

This is what I naively tried:

  mov ah, [0:46Ch]

....but the assembler complains: "invalid segment override". If I
understand correctly, a segment can be overridden only through a segment
register (es, cs, ds, ss). So here is my second attempt:

  push es
  xor ax, ax
  mov es, ax
  mov ah, [es:46Ch]
  pop es

This time, no more complaining from nasm. But isn't this batshit ugly? I
really don't like having to use the stack for such a seemingly simple
operation...

The question is: is this really the simplest way? Isn't there some more
straightforward method to read a byte from an arbitrary memory location?

Mateusz


Subject: Re: How to read a byte?
From: Robert Wessel
Newsgroups: alt.lang.asm
Organization: Forte - www.forteinc.com
Date: Thu, 19 Sep 2019 23:33 UTC
References: 1
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
From: robertwe...@yahoo.com (Robert Wessel)
Newsgroups: alt.lang.asm
Subject: Re: How to read a byte?
Message-ID: <iq38oet51sfuuju1hj08f7cjommmv9sbje@4ax.com>
References: <5d83f458$0$3523$426a74cc@news.free.fr>
User-Agent: ForteAgent/7.20.32.1218
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 41
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 19 Sep 2019 18:33:44 -0500
X-Received-Bytes: 2306
X-Received-Body-CRC: 846084972
View all headers
On 19 Sep 2019 21:34:16 GMT, Mateusz Viste <mateusz@wont.tell> wrote:

Here I am, trying to read the lowest 8 bits of the RTC timer on an 8086
PC. Assembly is not something I am comfortable with, hence the question
might be stupid (and certainly light years behind usual topics on this
group). Please bear with me.

This is what I naively tried:

 mov ah, [0:46Ch]

...but the assembler complains: "invalid segment override". If I
understand correctly, a segment can be overridden only through a segment
register (es, cs, ds, ss). So here is my second attempt:

 push es
 xor ax, ax
 mov es, ax
 mov ah, [es:46Ch]
 pop es

This time, no more complaining from nasm. But isn't this batshit ugly? I
really don't like having to use the stack for such a seemingly simple
operation...

The question is: is this really the simplest way? Isn't there some more
straightforward method to read a byte from an arbitrary memory location?


No, all memory accesses are segment+offset in real mode x86.  So if
you want to read the BDA, you'll need to point a segment register into
the vicinity.  I'd comment that is probably somewhat more common to
read the BDA by loading a segment register with 0x40, and reading with
an offset into the BDA, rather that from the start of the interrupt
vector table.  But I've see it done both ways.  Something like:

  push es
  mov ax,40h
  mov es, ax
  mov ah, [es:6Ch]
  pop es


Subject: Re: How to read a byte?
From: Mateusz Viste
Newsgroups: alt.lang.asm
Organization: Guest of ProXad - France
Date: Fri, 20 Sep 2019 08:45 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!cleanfeed3-a.proxad.net!nnrp1-1.free.fr!not-for-mail
From: mate...@wont.tell (Mateusz Viste)
Subject: Re: How to read a byte?
Newsgroups: alt.lang.asm
References: <5d83f458$0$3523$426a74cc@news.free.fr>
<iq38oet51sfuuju1hj08f7cjommmv9sbje@4ax.com>
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Date: 20 Sep 2019 08:45:52 GMT
Lines: 27
Message-ID: <5d8491c0$0$21586$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 20 Sep 2019 10:45:52 CEST
NNTP-Posting-Host: 82.64.0.151
X-Trace: 1568969152 news-3.free.fr 21586 82.64.0.151:56556
X-Complaints-To: abuse@proxad.net
View all headers
Hello Robert,

On Thu, 19 Sep 2019 18:33:44 -0500, Robert Wessel wrote:
No, all memory accesses are segment+offset in real mode x86.  So if you
want to read the BDA, you'll need to point a segment register into the
vicinity.

Thank you for your input. It does confirm that the "ugly" way of
backuping and pre-loading a segment register is indeed the only way to
access data outside of DS. I was hoping that I was missing on some obvious
trick that would make things less painful. No free lunch I guess.

I'd comment that is probably somewhat more common to read the
BDA by loading a segment register with 0x40, and reading with an offset
into the BDA, rather that from the start of the interrupt vector table.
But I've see it done both ways.  Something like:

  push es
  mov ax, 40h
  mov es, ax
  mov ah, [es:6Ch]
  pop es

Yes, I am aware. I like my version more, as it is a byte shorter, so I
will stick to it. :)

Mateusz


1
rocksolid light 0.7.2
clearneti2ptor