Migg 0 Newbie Poster

Hi all,

I have the following code :

section .data                           ;section declaration

MAX_LINHA	equ	1000

fich    db      "calculos.txt",0               ;Nome do ficheiro

flagLer   dd    00q                     ; O_RDONLY 
numFich   dd	0			; guarda o numero do ficheiro
nLidos	  dd	0
num1	dd	0
num2	dd	0
num3	dd	0
operacao dd 0
operacao2 dd 0

tamstr	dd	0

section .bss

linha	resb	MAX_LINHA

section .text                           ;section declaration

                        ;we must export the entry point to the ELF linker or
    global _start       ;loader. They conventionally recognize _start as their
                        ;entry point. Use ld -e foo to override the default.

_start:

; Abrir o ficheiro e guardar o handle em numFich

        mov     ecx,[flagLer] 	;second argument: flags
        mov     ebx,fich   	;first argument: nome do ficheiro
        mov     eax,5   	;system call number (sys_open)
        int     0x80    	;call kernel
		mov	[numFich], eax
	

; Ler no ficheiro cujo handle está em numFich
leitura:
        mov     edx,MAX_LINHA 	;tamanho da linha a ler
        mov     ecx,linha 	;apontador para a variavel a ler
        mov     ebx,[numFich]  	;apontador para o ficheiro
        mov     eax,3   	;system call number (sys_read)
        int     0x80    	;call kernel
		mov		[tamstr], eax	; guarda num. de bytes lidos
		
		
;	cmp	eax, 0
;	jle fim
	
	xor	eax, eax
	xor	ebx, ebx

	mov 	esi,linha
	cld
	mov	ecx, [tamstr]
	
ciclonum1:
	lodsb
	cmp	al, 0xa
	je	imprime
	cmp	al, '9'
	jg	letra1
	and	al, 0xF
	jmp	fim1

letra1:
	and	al, 0xF
	add	al, 9
fim1:

	shl	ebx,4
	add	ebx, eax
	loop ciclonum1
	mov	[num1], ebx
		
; Escrever linha no ecra
imprime:
		
        mov     edx,[tamstr] 	;third argument: message length
        mov     ecx,esi 	;second argument: pointer to message to write
        mov     ebx,1           ;first argument: file handle (stdout)
        mov     eax,4   	;system call number (sys_write)
        int     0x80    	;call kernel

; Fechar o ficheiro cujo handle está em numFich
fim:
        mov     ebx,[numFich]  	;apontador para o ficheiro
        mov     eax,6   	;system call number (sys_close)
        int     0x80    	;call kernel


; Sair do programa passando o controlo ao sistema operativo

        mov     ebx,0   	;first syscall argument: exit code
        mov     eax,1   	;system call number (sys_exit)
        int     0x80    	;call kernel

I'm using Linux OS (32 bits) and nasm.

I have a original file with :

38
13
+

I want to read the first number and and to num1, read the second number and add to num2 and read the operator and add do operacao.

With this code when I print the esi I got :

13
+

But the num1 does not receive the value 38.

Can you help me with this problem please ?

Thanks,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.