Advertisement
ewelina_r

Untitled

May 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #----------------------------------------------------------------
  2. # Program lab_1.s - Asemblery Laboratorium IS II rok
  3. #----------------------------------------------------------------
  4. #
  5. #  To compile: as -o lab_1.o lab_1.s
  6. #  To link:    ld -o lab_1 lab_1.o
  7. #  To run:     ./lab_1
  8. #
  9. #----------------------------------------------------------------
  10.  
  11.     .equ    kernel,0x80 #Linux system functions entry
  12.     .equ    write,0x04  #write data to file function
  13.     .equ    exit,0x01   #exit program function
  14.     .equ    stdout,0x01 #handle to stdout
  15.     .equ    zero,0x00
  16.  
  17.     .data
  18.    
  19. starttxt:           #first message
  20.     .ascii  "Start\n"
  21. endtxt:             #second message
  22.     .ascii  "Finish\n"
  23. arg1:               #first argument
  24.     .byte       1
  25. arg2:               #second argument
  26.     .word       2
  27. arg3:               #third argument
  28.     .long       3
  29. result:             #result
  30.     .long       999
  31.  
  32. .equ    startlen, endtxt - starttxt
  33. .equ    endlen, arg1 - endtxt
  34.  
  35.     .text
  36.     .global _start
  37.    
  38. _start:
  39.     MOVL    $write,%eax
  40.     MOVL    $stdout,%ebx
  41.     MOVL    $starttxt,%ecx
  42.     MOVL    $startlen,%edx
  43.     INT $kernel
  44.    
  45.     NOP
  46.    
  47.     MOVL    $zero,%eax
  48.     MOVL    $zero,%ebx
  49.     MOVB    arg1,%al
  50.     MOVW    arg2,%bx
  51.     MOVL    arg3,%ecx
  52.     ADD %ebx,%eax
  53.     SUB %ecx,%eax
  54.     MOVL    %eax,result
  55.    
  56.     NOP
  57.    
  58.     MOVL    $write,%eax
  59.     MOVL    $stdout,%ebx
  60.     MOVL    $endtxt,%ecx
  61.     MOVL    $endlen,%edx
  62.     INT $kernel
  63.    
  64.     NOP
  65. theend:
  66.     MOVL    $exit,%eax
  67.     INT $kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement