Re: comp.lang.asm.x86 Is Undergoing Testing
- From: "Wolfgang Kern" <nowhere@xxxxxxxx>
- Date: Mon, 25 May 2009 00:17:08 +0200
Herbert Kleebauer posted:
Frank Kotler wrote:
So how do you think this updated FAQ should be organized?
Isn't the purpose of a FAQ to reduce the amount of simple questions
which are repeated again and again? I don't think ala or clax
has any problem with such questions. As I see it, the problem
of ala and clax is the opposite: to less traffic and to less
questions. So, if a FAQ fulfills it's destiny, things will become
even worse. More important than to give solutions for a collection
of problems is, to show that it is very easy to make your first
assembly program. And with "make" I don't mean to generate
a sequence of OS calls which does the job, but writing a sequence
of CPU instruction which do all themselves.
How much CPU instructions and addressing modes must you know
to write a simple x86 "Hello World" program? I think three
instructions and three addressing modes are sufficient:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move src,dest ; copy the data at "src" location to the "dest" location"dest" location
sub src,dest ; subtract the data at "src" location from the data at
beq address ; jump to "address" if the result of the last sub was zeroprogram:
"src" can be an immediate operand (#123), one of four register (r0-r3)
or a memory location.
"dest" can be one of four register (r0-r3) or a memory location.
"src" and "dest" must not be both memory locations.
A memory location is specified by a segment start address stored in
one of four segment registers (s0-s3) and an offset, which can be
given directly ( move #123,456{s0} ) or be stored in a data register
( move #123,(r2){s0} ).
memory address = [si]*16 + offset
If in the "move" instruction one operand is a data register (r0-r3), the
other can be a segment register (s0-s3). "move" and "sub" can be used for
bytes (8 bit), words (16 bit) or longs (32 bit) (move.b, move.w, move.l).
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Now, that's all you need to know to write your first "Hello World"
@=$100
00000100: b8 b800 move.w #$b800,r0
00000103: 8e c0 move.w r0,s1
00000105: 66 b9 0000012f move.l #text,r2
0000010b: 66 bb 00000668 move.l #10*160+40,r3
00000111: b8 3600 move.w #$3600,r0
00000114: 67 8a 01 loop: move.b (r2){s0},r0
00000117: 2c 00 sub.b #0,r0
00000119: 0f 84 fee3 beq.w 0
0000011d: 81 e9 ffff sub.w #-1,r2
00000121: 67 26 89 03 move.w r0,(r3){s1}
00000125: 81 eb fffe sub.w #-2,r3
00000129: 28 c0 sub.b r0,r0
0000012b: 0f 84 ffe5 beq.w loop
0000012f: 68 65 6c 6c 6f 20
00000135: 77 6f 72 6c 64 00 text: dc.b "hello world",0
You will get a binary of 59 bytes where you know the purpose
of any of them.
Fine for newbies who search for a quick start Herbert!
but I can't see a reason for the 66' in the above text-mode version.
Perhaps just to create an overoll/exception for out of bound char/pixel ?
__
wolfgang
btw: I didn't forget the challenge (C vs.ASM) from the last year,
but the hex-dump you posted didn't survive the transportation-phase
(I had to reinstall all my PC's after a heavy delayed move to my new
and hopefully final residential location).
If you don't mind please repost or even find any other C-example
where I can satisfy my LL-ego on :) :)
.
- Follow-Ups:
- Re: comp.lang.asm.x86 Is Undergoing Testing
- From: Herbert Kleebauer
- Re: comp.lang.asm.x86 Is Undergoing Testing
- References:
- Re: comp.lang.asm.x86 Is Undergoing Testing
- From: Nathan Baker
- Re: comp.lang.asm.x86 Is Undergoing Testing
- From: Frank Kotler
- Re: comp.lang.asm.x86 Is Undergoing Testing
- From: Herbert Kleebauer
- Re: comp.lang.asm.x86 Is Undergoing Testing
- Prev by Date: Re: comp.lang.asm.x86 Is Undergoing Testing
- Next by Date: Re: [OT] Medjugorje
- Previous by thread: Re: comp.lang.asm.x86 Is Undergoing Testing
- Next by thread: Re: comp.lang.asm.x86 Is Undergoing Testing
- Index(es):
Relevant Pages
|