  assembly & linux
  jan wagemakers, janw@mail.dma.be
  21/07/1997
  ɍ N, isaji@mxu.meshnet.or.jp
  24 jan 1998

  (󒍁F̕http://bewoner.dma.be/JanW/̂̂łBȉ
  uweby[Wv͂urlwĂ܂)B"x86݊}V/linuxIy
  [eBOVXe"ŃAZuvO~Og݂ɂ
  ďꂽweby[WłB
  ______________________________________________________________________

  ڎ

  1. XV
  2. AZu & DOS
  3. AZu & Linux
  4. AZu & Linux -  -
     4.1 NASM̗݂Ă݂܂傤F
     4.2 gaŝQ̗F
     4.3 GASɃ}NǉF
     4.4 ncursesg

  5. A

  ______________________________________________________________________

  1.  XV

  ̃eXgsĂ邤ɂ[ƂɋCÂ܂B
  weby[WɒǉĂƎv܂BȉAV݂₷
  邽߂ɍXV܂B

     xx/06/1997 : start linux & assembler z[y[W
     05/07/1997 : change h.2.1.3. (add macro's to gas)
     21/07/1997 : change h.2.1.4. (ncurses (sat_color.s))

  2.  AZu & DOS

  AZu...킯ăAZuŃvO~O邱ƂC
  Ă܂BdosŁAƃAZugĂ܂B̎
  ݂ɂdkopie܂܂Bdkopie  2mƂgtH[}bg
  Rs[ł悤ɂfBXNRs[vOłB

  2mɂĂ͈̏ȉQƂĉF the homepage of ciriaco
  garcia de celis

  dkopie̍ŐVł͌dkopie v3.0łB
  http://www.simtel.net/pub/simtelnet/msdos/diskutil/dkopie30.zip _
  E[hł܂B

  3.  AZu & Linux

  DOS݂͌̃Rs[^ł͕͗słBWindowsgCɂȂ
  BLinuxgĂ̂łAOŜłƂĂKɂ
  ܂  :-)B UNIX & Linux ł͕WIȃvO~O C  C++
  łB͑̋@\Ăđ̃Rs[^VXeɂڐA
  Ă܂BAZuĝLinuxƃAZu̖͂ɂ͒
  Rł܂BȉA݂̎ɂĂ̌ʂ܂Ƃ߂܂B낢ȏ
  񋟂Ăꂽ fidonet (assembler.028, 80xxx, linux.b, linux) ̕
  XɊӂ܂B

  4.  AZu & Linux -  -

  LinuxAZuvOƂɂ͑̉\܂B
  ߂ɂǂ̃AZugIׂ܂BGAS(AS)ĝ悢ł
  Bgas͂قƂǂLinuxfBXgr[V̕WƂȂĂAZ
  ułB gaš_gasAT&T-syntaxgĂ邱ƂłB
  Intel-syntaxƑ傫Ă܂B DOS[U[͂قƂ
  Intel-syntaxgĂ܂B

  AT&T-syntaxɂĂ̂ڍׂȏ infot@Cɂ܂B
  infot@ChtmltH[}bgɕϊ܂B

  Intel݊syntaxQƂ鎞nasmŃvOƂł܂B

  4.1.  NASM̗݂Ă݂܂傤F

  from the 80xxx-fidonet-area :

  = deze bewaar ik : asm =================================================keepit=
  from : james vahn                          17-apr-97  15:20:22  1:346/15.1
  to   : jan wagemakers                                           2:292/8133.23
  subj : nasm & linux
  =======================================================================rem_asm=

   * 80xxx ̈p
   jw> f܂AĂ͈͂łcvOĂяo悤
   jw> Ă܂Bnasmlinux 100% AZuvOǂ̂悤
   jw> ̂m肽łB

  oOtBbNXꂽnasm-0.94gāA\[Xȉ̂悤ɃAZu܂B
     nasm -f elf hello.asm
     gcc hello.o -o hello
     strip hello

  wԂƂ񂠂܂   :-)

  ______________________________________________________________________
  ;-------------nasm's standalone hello-world.asm for linux --------
  section .text
  extern puts
  global main

  main:
     push dword msg                ;stash the location of msg on the stack.
     call puts                     ;call the 'puts' routine (libc?)
     add esp, byte 4               ;clean the stack?
     ret                           ;exit.

  msg:
     db "hello world!",0
  ______________________________________________________________________

  --- timed 1.01
   * origin: james vahn (jvahn@short.circuit.com) (1:346/15.1)
  ===============================================================================

  ̗łputšĂяo͉ʂɃeLXg\̂Ɏg
  Bputs ĉ̂ŁALinuxŃ[h郉Cu̕W\
  BAZułs@܂Binterrupts łB
  LinuxJ[l̍̃o[WŕύX邩Ȃ̂ł̊荞
   (interrupts)ĝ͂߂܂B

  4.2.  gaŝQ̗F

  AZu.028DꂽTvpieter de jongo܂B

  P)    putšĂяog

  ______________________________________________________________________
   .text
  message:
   .ascii "hello world!\0"
   .align 4
   .globl main
  main:
   pushl %ebp
   movl %esp,%ebp
   #call ___main
   pushl $message
   call puts
   addl $4,%esp
   xorl %eax,%eax
   movl %ebp,%esp
   popl %ebp
   ret
  ______________________________________________________________________

  ƂāA

          as hello.s -o hello.o
          gcc hello.o -o hello

  ƃRpC܂B

  Q) int 80hg

  ______________________________________________________________________
   .text
  message:
   .ascii "hello, world!\12\0"
   .align 4
   .globl _hw
  _hw:
   movl $4, %eax
   movl $1, %ebx
   movl $message, %ecx
   movl $15, %edx
   int $0x80
   movl $1, %eax
   movl $0, %ebx
   int $0x80
  ______________________________________________________________________

  ƂāA

          as hello.s -o hello.o
          ld hello.o -e _hw -o hello
          (_hw = Gg|Cg)

  ƃRpC܂B

  4.3.  GASɃ}NǉF

  changed on : 5 Jul 1997

  }NgƂɂăvO~O̕GȂł܂B
  hLgŁAGAS̓}N߂łAZuŃ}Ng
  GASPg˂΂ȂȂƂƂǂ݂܂B

  .. eXgĂ݂GNU-C infot@Cǂ񂾂Ƃ
  GAS(as)găAZuvOɃ}N邱Ƃł邱Ƃ
  ܂BȉAseXgЉ܂BGAS  }N ̉\
  ݂Ă܂ (󒍁Fdummy.dummyƂt@C邩`FbN
  vOł)B

  test_fopen.s̃\[XF

  ______________________________________________________________________
          .include "include.asm"

          .globl main
  main:
          _print hallo            # ^Cg\
          _open bestand mode      # t@C'dummy.dummy'J
          cmp $0,%eax             # Success?
          je file_error           # ߁BG[bZ[W̕\
          _close %eax             # t@C
          _print bestaat          # 'exist'ƕ\
          jmp einde               # vOI
  file_error:
          _print bestaat_niet     # 'doesn't exist'ƕ\
  einde:
          ret                     # The End ;-)

  hallo:
   .string "Test Linux Program ;-) \n"
  bestaat:
   .string "The file dummy.dummy exists..."
  bestaat_niet:
   .string "The file dummy.dummy doesn't exist..."
  bestand:
   .string "dummy.dummy"
  mode:
   .string "r"

   .END
  ______________________________________________________________________

  include.asm

  ______________________________________________________________________
   .MACRO _print message
   # start _print message
   pushl $\message
   call puts
   addl $4,%esp
   # end   _print message
   .ENDM

   .MACRO _open file mode
   # start _open t@C[h
   pushl %ebp
   movl %esp,%ebp
   pushl $\mode
   pushl $\file
   call fopen
   addl $8,%esp
   movl %eax,-4(%ebp)
   # %eax = t@Cnh
   #        -  %eax = 0 Ȃt@C͂Ȃ
   #        -  %eax >< 0 %eax Ȃt@Cnh
   popl %ebp
   # end   _open t@C[h
   .ENDM

   .MACRO _close filehandle
   # start _close t@Cnh
   pushl \filehandle
   call fclose
   addl $4,%esp
   # end   _close t@Cnh
   .ENDM
  ______________________________________________________________________

  ƂāA

          as test_fopen.s -o test_fopen.o
          gcc test_fopen.o -o test_fopen

  ̂悤ɃRpC܂B

  4.4.  ncursesg

  1997N721 ύXF

  Ncurses ̓eLXgx[XLinuxvOƂɎg֐̃Cu
  łB

  ȉAsAȃAZuvOncurseesǂ̂悤ɌĂяo
  邽߂ɃTvvO܂BƂ̂ł͂Ȃ
  ܂񂪓݂ɂ͂悢Ǝv܂ :-) B

  sat_color.s

  ______________________________________________________________________
          .include "/home/jan/assembler/include/ncurses.asm"

          .globl main
  main:
          _initscr
          _start_color
          _init_pair $1,$2,$4
          _init_pair $2,$0,$6
          _init_pair $3,$3,$4
          _init_pair $4,$4,$4             # Hide the flashing cursor

          call cls                        # clear screen/init colors.

          _use_pair $0x00000200           # 00 00(NORMAL) 02(PAIR) 00
          _locate $1,$0
          _printw $titel
          _locate $46,$0
          _printw $pd
          _use_pair  $0x00200100          # 00 20(BOLD) 01(PAIR) 00

          _locate $32,$12
          _printw $world

          _use_pair  $0x00200300          # 00 20(BOLD) 03(PAIR) 00

          movl $0,%esi
  lus:
          movb tabel(%esi),%dl            # %dl = X(%esi)
          incl %esi
          movb tabel(%esi),%cl            # %cl = Y(%esi)
          incl %esi
          cmpb $242,%cl
          jne n242_1
          movl $0,%esi
          jmp lus
  n242_1:
          movl %esi,%edi
  redo:
          movb tabel(%edi),%dh            # %dh = X(%esi + 1)
          incl %edi
          movb tabel(%edi),%ch            # %ch = Y(%esi + 1)
          cmpb $242,%ch
          jne  n242_2
          movl $0,%edi
          jmp redo
  n242_2:
          movl $leeg,%ebp
          call print_item
          movl $linux,%ebp
          movb %ch,%cl
          movb %dh,%dl
          call print_item

          pushl $160000                   # C : usleep(....);
          call usleep                     # Wait-loop
          addl $4,%esp

          _refresh
          jmp lus
          _endwin
          ret

  print_item:
          pushal
          movzbl %cl,%eax
          movzbl %dl,%ebx
          _locate %ebx,%eax
          _printw %ebp
          popal
          ret

  cls:
          _use_pair $0x00000200           # 00 00(NORMAL) 02(PAIR) 00
                                          # Color of the first line
          movb $0,%cl
          movb $0,%dl
  cls_lus:
          movl $chr32,%ebp
          call print_item
          incb %dl
          cmpb $79,%dl
          jna cls_lus
          pushal
          _use_pair  $0x00000400          # 00 00(NORMAL) 04(PAIR) 00
                                          # Color of the rest of the screen
          popal
          xorb %dl,%dl
          incb %cl
          cmpb $25,%cl
          jna cls_lus
          ret

  linux:
   .string "Linux"
  leeg:
   .string "     "
  chr32:
   .string " "
  world:
   .string "World Domination"
  titel:
   .string "sat_color.s - 1997 Jan Wagemakers -"
  pd:
   .string "Donated to the Public Domain :-)"
  tabel:
   .include "cirkel.dat"
   .byte 242,242

   .END
  ______________________________________________________________________

  (󒍁F擪ncurses.asm̃CN[hfBNg͓KɕύXĉ
  )

  cirkel.dat

  ______________________________________________________________________
   .byte  72 , 12
   .byte  71 , 13
   .byte  69 , 15
   .byte  66 , 17
   .byte  62 , 18
   .byte  56 , 20
   .byte  51 , 21
   .byte  44 , 21
   .byte  38 , 21
   .byte  31 , 21
   .byte  24 , 21
   .byte  18 , 20
   .byte  13 , 19
   .byte  8 , 17
   .byte  5 , 16
   .byte  3 , 14
   .byte  2 , 12
   .byte  2 , 10
   .byte  3 , 8
   .byte  6 , 7
   .byte  10 , 5
   .byte  15 , 4
   .byte  20 , 3
   .byte  27 , 2
   .byte  33 , 2
   .byte  40 , 2
   .byte  47 , 2
   .byte  53 , 3
   .byte  59 , 4
   .byte  63 , 5
   .byte  67 , 7
   .byte  70 , 8
   .byte  71 , 10
  ______________________________________________________________________

  /home/jan/assembler/include/ncurses.asm

  ______________________________________________________________________
   # ncurses.asm          - donated to the public domain by Jan Wagemakers -
   # derived of the following C-program
   # #include
   #
   # int main(void)
   # {
   #     initscr();  /* cursesCȕ */
   #     move(10, 2);  /* J[\ X: 2, Y: 10 ɒu */
   #     printw("Hello, World !"); /* \ */
   #     refresh(); /* ʂ "Hello, World !" u */
   #     getch(); /* L[̂҂ */
   #     endwin(); /* deinit the curses libraries. */
   #     return 0;
   # }
   #
   # CɂĂ悭mȂ̂ňȉ͈ႤƂ܂B
   # CƂ͂߂킸ĉB
   # ncursesgĉʂɉƂ͈ȉ̃}NĂяo܂B
   #      1. _initscr
   #      2. _locate x y  (x,y = ʂ̍W)
   #      3. _printw message
   #      4. _refresh
   #      5. _endwin      (win̏I.... Ȃɂł ;-)

   .MACRO _initscr
   # start _initscr
   call initscr
   # end   _initscr
   .ENDM

   .MACRO _locate x y
   # start _locate x y
   pushl \x
   pushl \y
   movl stdscr,%eax
   pushl %eax
   call wmove
   addl $12,%esp
   # end   _locate x y
   .ENDM

   .MACRO _printw message
   # start _print message
   pushl \message
   call printw
   addl $4,%esp
   # end   _printw message
   .ENDM

   .MACRO _refresh
   # start _refresh
   movl stdscr,%eax
   pushl %eax
   call wrefresh
   addl $4,%esp
   # end   _refresh
   .ENDM

   .MACRO _endwin
   # start _endwin
   call endwin
   # end   _endwin
   .ENDM

  # Colors  ncurses. (15/07/97)
  # - After _initscr , call _start_color
  # - Init with _init_pair a color-pair.
  # - With _use_pair select a color-pair.

   .MACRO _start_color
   # start _start_color
   call start_color
   # end   _start_color
   .ENDM

   .MACRO _init_pair pair foreground background
   # start _init_pair
   pushl \background
   pushl \foreground
   pushl \pair
   call init_pair
   addl $12,%esp
   # end   _init_pair
   .ENDM

   .MACRO _use_pair pair
   # start _use_pair
   movl \pair,%eax
   #                |        |  %ah   |  %al   |
   # %eax = xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
   #                    |        |
   #                    |        |
   #                    |        +----> gJ[yA(color-pair)ԍ
   #                    +-------------> 00 = m[} , 20 = BOLD
   pushl %eax
   movl stdscr,%eax
   pushl %eax
   call wattr_on
   addl $8,%esp
   #end _use_pair
   .ENDM
  ______________________________________________________________________

          as sat_color.s -o sat_color.o
          gcc sat_color.o -o sat_color -lncurses

  ƃRpCA./sat_colorŎs܂(󒍁F̃vOs
  ƐwỉʒɗΕŁuWorld DominationvA̎F
  uLinuxv邮f܂Bcolor_xtermȂǂŎsĂ݂ĉ
  )B

  5.  A

  AZuɊւWĂ܂ :-) B

     Jan Wagemakers
     Internet : JanW@mail.dma.be
     Fidonet : 2:292/854.19

