Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.




 
; x86_64 linux nasm
 
section .data
localFileName: db "input.txt", 0
rootFileName: db "/initrd.img", 0
 
section .text
 
global _start
 
_start:
 
  ; open file in current dir
  mov rax, 2
  mov rdi, localFileName
  xor rsi, rsi
  mov rdx, 0
  syscall
  push rax
 
  mov rdi, rax ; file descriptior
  mov rsi, 0 ; offset
  mov rdx, 2 ; whence
  mov rax, 8 ; sys_lseek
  syscall
 
  ; compare result to actual size
  cmp rax, 11
  jne fail
 
  ; close the file
  pop rdi
  mov rax, 3
  syscall
 
  ; open file in root dir
  mov rax, 2
  mov rdi, rootFileName
  xor rsi, rsi
  mov rdx, 0
  syscall
  push rax
 
  mov rdi, rax ; file descriptior
  mov rsi, 0 ; offset
  mov rdx, 2 ; whence
  mov rax, 8 ; sys_lseek
  syscall
 
  ; compare result to actual size
  cmp rax, 37722243
  jne fail
 
  ; close the file
  pop rdi
  mov rax, 3
  syscall
 
  ; test successful
  mov rax, 60
  mov rdi, 0
  syscall
 
  ; test failed
  fail:
    mov rax, 60
    mov rdi, 1
    syscall
 