Search     or:     and:
 LINUX 
 Language 
 Kernel 
 Package 
 Book 
 Test 
 OS 
 Forum 
 iakovlev.org 
 Languages
 С
 GNU С Library 
 Qt 
 STL 
 Threads 
 C++ 
 Samples 
 stanford.edu 
 ANSI C
 Libs
 LD
 Socket
 Pusher
 Pipes
 Encryption
 Plugin
 Inter-Process
 Errors
 Deep C Secrets
 C + UNIX
 Linked Lists / Trees
 Asm
 Perl
 Python
 Shell
 Erlang
 Go
 Rust
NEWS
Последние статьи :
  Rust 07.11   
  Go 25.12   
  EXT4 10.11   
  FS benchmark 15.09   
  Сетунь 23.07   
  Trees 25.06   
  Apache 03.02   
  SQL 30.07   
  JFS 10.06   
  B-trees 01.06   
 
TOP 20
 Go Web ...718 
 Trees...480 
 Python...311 
 Ethreal 4...303 
 2.0-> Linux IP Networking...280 
 Steve Pate 3...280 
 Secure Programming for Li...268 
 Mike Perry...252 
 Rubni-Corbet -> Глав...239 
 Stewens -> IPC 7...237 
 Rubni-Corbet -> Глав...236 
 TCP 3...234 
 Rubni-Corbet -> Глав...232 
 TCP 2...226 
 Стивенс 9...222 
 C++ Templates 4...217 
 Stevens-> Глава 25...216 
 Rodriguez 6...211 
 Daniel Bovet 2...210 
 UML 3...205 
 
  01.11.2017 : 2330974 посещений 

iakovlev.org

1.3. Макросы в GAS :

С помощью макросов можно облегчить свою жизнь .
___ test_fopen.s __________________________________________________________
 
         .include "include.asm"
 
         .globl main
 main:
         _print hallo            # Print title
         _open bestand mode      # Open the file 'dummy.dummy'
         cmp $0,%eax             # Success?
         je file_error           # No, Print error message
         _close %eax             # Yes, Close file
         _print bestaat          # Print text 'exist'
         jmp einde               # End of prg.
 file_error:
         _print bestaat_niet     # Print text '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 file mode
  pushl %ebp
  movl %esp,%ebp
  pushl $\mode
  pushl $\file
  call fopen
  addl $8,%esp
  movl %eax,-4(%ebp)
  # %eax = file-handle
  #        - if %eax = 0 then the file doesn't exist
  #        - if %eax >< 0 %eax is the file-handle
  popl %ebp
  # end   _open file mode
  .ENDM
 
  .MACRO _close filehandle
  # start _close filehandle
  pushl \filehandle
  call fclose
  addl $4,%esp
  # end   _close filehandle
  .ENDM
 ___________________________________________________________________________
 
 as test_fopen.s -o test_fopen.o
 gcc test_fopen.o -o test_fopen
 

1.4. ncurses

Ncurses - библиотека для написания программ с текстовым интерфейсом . В данном примере по экрану циклически перемещается текстовая строка .
___ 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                     # Wacht-lus
         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
 ___________________________________________________________________________
 
 ___ 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 -
  # afgeleid van onderstaand C-programma
  # #include <curses.h>
  #
  # int main(void)
  # {
  #     initscr();  /* Init the curses libraries */
  #     move(10, 2);  /* Place the cursor at X: 2, Y: 10 */
  #     printw("Hello, World !"); /* Print anything */
  #     refresh(); /* This places the "Hello, World !" on the physical screen */
  #     getch(); /* Wait for keypress */
  #     endwin(); /* deinit the curses libraries. */
  #     return 0;
  # }
  #
  # Because I know NOT very much of C The following can be incorrect.
  # Please, do not hesitate to make corrections :-)
  # So, when you want to put something on the screen with ncurses, you call
  # the following macro's :
  #      1. _initscr
  #      2. _locate x y  (x,y = screen coordinates)
  #      3. _printw message
  #      4. _refresh
  #      5. _endwin      (end win.... sounds nice, isn't it ;-)
 
  .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 and 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
  #                    |        |
  #                    |        |
  #                    |        +----> Number of color-pair
  #                    +-------------> 00 = Normaal , 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
 sat_color
 
Оставьте свой комментарий !

Ваше имя:
Комментарий:
Оба поля являются обязательными

 Автор  Комментарий к данной статье