filename:
.asciz "22names.txt"
dec32_format:
.string "%d\n"
.section .text
.globl main
main:
pushl $filename
call read_file
#------------------------------------------------------------------------------
.type read_file, @ function
read_file:
xor %eax, %eax
xor %ebx, %ebx
xor %ecx, %ecx
xor %edx, %edx
mov $0x05, %al # 5 sys_open(const char *, int, int)
mov 4(%esp), %ebx # load string pointer into register
xor %ecx, %ecx # O_RDONLY (open read only)
int $0x80
mov %eax, %esi # file descriptor
jmp read
read:
mov $0x03, %al # 3 sys_read(unsigned int, char *, size_t)
mov %esi, %ebx # file descriptor (unsigned int)
lea (%esp), %ecx #
mov $0x01, %dl # read only 1 char (third arg)
int $0x80 # sys_call
xor %ebx, %ebx # clear out ebx
cmp %eax, %ebx # compare eax and ebx
je exit # if EAX && EBX == NULL, EOF
mov $0x04, %al # 4 sys_write(unsigned int, const char *, size_t)
mov $0x01, %bl # write to STDOUT
mov $0x01, %dl # write one character
int $0x80 # call it
jmp read # read the next char
exit:
xor %ebx, %ebx
mov $0x01, %al
int $0x80
The code works perfectly fine in that it reads the file and writes its contents on the console. But that's not what I need. I need to store the current character in a register so I can use it to do some computations. But this code doesn't seem to be storing the character in any register. I'm using this code as a template (I got it from a website) but I'm having no luck modifying it to do what I need. So can you please tell me how I need to change it?
Thanks!
This post has been edited by carnivroar: 04 July 2012 - 08:39 PM

New Topic/Question
Reply


MultiQuote






|