Ads

Sunday 6 October 2013

Microprocessor Architecture FILE HANDLING

Rollno: 2431
Name: Venkatesh Lokare

SECTION .data
msg1: db "file did not open",10
len1: equ $-msg1
msg2: db "opened",10
len2: equ $-msg2
msg3: db "closing.....",10
len3: equ $-msg3

file_name : db 'aaa.txt',0

SECTION .bss
fd: resd 1
buf: resb 100
len: resb 2

%macro disp 2
mov eax,04
mov ebx,01
mov ecx,%1
mov edx,%2
int 0x80
%endmacro

SECTION .text
main:

mov eax,05
mov ecx,00
mov ebx,file_name
mov edx,0777
int 0x80

mov [fd],eax ;move file discriptor in fd
bt eax,31  ;check is first bit is 0 or 1
jnc open

disp msg1,len1
jmp exit

open:
disp msg2,len2

loop:
mov edx, 100
mov ecx, buf
mov ebx, [fd]
mov eax, 03
int 0x80

mov [len],eax

cmp eax,0
jz close ;file read completed

disp buf,[len]
jmp loop

close:
disp msg3,len3
mov eax,06
mov ebx,fd
int 0x80

exit:
mov ebx,0
mov eax,1
int 0x80



;;;;;;;;;;;;;;;output;;;;;;;;;;;;;;;;;;;
;[pict@localhost ~]$ cd 2431
;[pict@localhost 2431]$ nasm -f elf -l file.lst file.asm
;[pict@localhost 2431]$ ld -o file file.o
;ld: warning: cannot find entry symbol _start; defaulting to 0000000008048080
;[pict@localhost 2431]$ ./file
;opened
;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
;ccccccccccccccccccccccccccccccccccccccc
;ddddddddddddddddddddddddddddddddddddddd
;eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
;fffffffffffffffffffffffffffffffffffffff
;ggggggggggggggggggggggggggggggggggggggg
;closing.....
;[pict@localhost 2431]$







No comments:

Post a Comment