Re: Book on Assembly




Julienne Walker wrote:
What would you like to see in a book on assembly language?

Information that CAN NOT be obtained by reading one of the many books
on *other* programming languages. For instance, for each and every
machine instruction (or logical grouping of related instructions), give
a few interesting examples of how to put those instructions to good
use. Show them how to manipulate bits, nibbles, bytes, words, etc.
with as many interesting instruction combinations as you can think of.

If the book is intended to be for beginners, then DO NOT put
information in there (nor write macros for them) showing them how to
duplicate 17 different High-Level control constructs. There is *only
one* control construct in assembly -- Branch. Its implementations on
the x86 platform are things like Jump Conditionally, Jump
Unconditionally, and Call Routine. Just give them the a set of tools,
show them the specs of their goal, then let 'em build their control
construct from scratch!

These are the questions I've asked myself when designing my book on x86
assembly language. I want it to be complete for a beginner to assembly,
but not so complete as to be overwhelming. As such, I've avoided
extensions such as MMX and SSE, as well as floating-point for the time
being.

Attached is a program based on examples given in a second-course
(intermediate level) Java text. If you think it represents something
that wouldn't be "overwhelming" for a "beginner to assembly" then
please explain why.

// birthday.hla - demonstrates use of a 'set' class
// for Linux and Win32

program birthdaydemo;
#include("stdlib.hhf")

const
Size :dword := 365;
Trials :dword := 100;

// define a limited boolean set class
// we only need set, get, and clear for this demo
type
boolset:
class
var
setArray :boolean[Size];
endvar;

procedure create; @returns("esi");
procedure destroy;
method set( element:dword );
method get( element:dword ); @returns("eax");
method clear;
endclass;
endtype;

procedure boolset.create; @nodisplay; @noframe;
begin create;

push( edi );
push( eax );
push( ebx );
if ( esi = 0 ) then
mem.alloc( @size( boolset ) );
mov( eax, esi );
endif;
mov( &boolset._VMT_, this._pVMT_ );

lea( edi, this.setArray );
mov( 0, eax );
while (eax < Size) do
mov( false, (type dword [edi+eax*4]) );
inc( eax );
endwhile;
pop( ebx );
pop( eax );
pop( edi );
ret();

end create;

procedure boolset.destroy; @nodisplay; @noframe;
begin destroy;

if ( isInHeap( esi ) ) then
mem.free( esi );
endif;
ret();

end destroy;

method boolset.set( element:dword ); @nodisplay;
begin set;

push( edi );
push( eax );
lea( edi, this.setArray );
mov( element, eax );
mov( true, (type dword [edi+eax*4]) );
pop( eax );
pop( edi );

end set;

method boolset.get( element:dword ); @nodisplay;
begin get;

push( edi );
push( ebx );
lea( edi, this.setArray );
mov( element, ebx );
mov( (type dword [edi+ebx*4]), eax );
pop( ebx );
pop( edi );

end get;

method boolset.clear; @nodisplay;
begin clear;

push( edi );
push( eax );
push( ebx );
lea( edi, this.setArray );
mov( 0, eax );
while (eax < Size) do
mov( false, (type dword [edi+eax*4]) );
inc( eax );
endwhile;
pop( ebx );
pop( eax );
pop( edi );

end clear;

readonly
VMT( boolset );
endreadonly;

static
daysOfYear :boolset;
endstatic;

var
total :dword;
count :dword;
numPeople :dword;
birthday :dword;
endvar;

begin birthdaydemo;

rand.randomize();
daysOfYear.create();
mov( 0, total );

for ( mov( 0, count ); count < Trials; inc( count ) ) do

mov( 1, numPeople );
mov( true, ebx );

while ( ebx = true ) do

rand.range( 0, Size - 1 );
mov( eax, birthday );
daysOfYear.get( birthday );

if ( eax = true ) then

mov( numPeople, eax );
mov( total, ecx );
add( ecx, eax );
mov( eax, total );
break;

endif;

daysOfYear.set( birthday );
inc( numPeople );

endwhile;

daysOfYear.clear();

endfor;

mov( total, eax );
cdq();
idiv( Trials, edx:eax );
stdout.puts("For ");
stdout.putu32( Trials );
stdout.puts(" trials, the average number" nl );
stdout.puts("of people in the group before there were" nl );
stdout.puts("two people with the same birthday was ");
stdout.putu32( eax );
stdout.puts("." nl );
daysOfYear.destroy();

end birthdaydemo;

Happy Birthday Hutch-- !! ;-)

Nathan.

.



Relevant Pages

  • Re: Macro2D
    ... õ1, eax", 0 ... db "push striIIi", NL ... db ".2: cmp edi, ebp", NL ... db ".4: mov eax, edi", NL ...
    (alt.lang.asm)
  • One RosAsm Pre-parser
    ... cmp eax 0 | ja L0<< ... mov ecx, D ...
    (alt.lang.asm)
  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)
  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)
  • Re: Interesting Web Site on Open Source Development
    ... mov D§esp 0DEADBEEF call Code04013A0 ... call Code0401100 push eax lea eax D§esp+014 push Data0402124 ... push eax call 'USER32.wsprintfA' add esp 0C push 030 lea ecx D§esp+014 push ecx ...
    (alt.lang.asm)