0
Code update: I followed the tips and tried to stop the loop in the update section. I’m still working on the segmentation failure, however. And I need to check this loop, I don’t think it’s quite right....
Hello, I’m writing code to perform a series of sequential tasks in NASM syntax. At first I could not even compile, but now although Compile, and run Linker, when running the program in the terminal I get the message "Segmentation failure (image of the saved kernel)". Since I’m terrible at this, and I’m just beginning to understand what Assembly’s logic is, I can’t find the error. Anybody got any tips? It’s for linux, but in the slides I took from some lessons on the internet, in Ubuntu people use this mov eax,1 - int 80h as a system call.
section .data
array DB 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,82,30,30,30
divisor DB 10
result DW 0
section .text
global _start
_start:
xor ax,ax
xor cx,cx
xor bl,bl
mov si,[array+0]
mov cx,20
mov bl,[si]
loopx:
cmp [si],bl
jle update
resume:
inc si
loop loopx
update:
mov bl,[si]
cmp [array+80],bl
je c_soma
jmp resume
xor bh,bh
mov [result],bx
mov ax,[result]
mov bl,[divisor]
div bl
mov bl,al
jmp c_soma
body_soma:
sub al,1
add bl,al
jmp c_soma
c_soma:
cmp al,0
jne body_soma
mov eax,1
int 0x80
the goal is to make a sequence of actions: first go through the vector of 20 positions and find the lowest value by updating the register. When you finish going through the vector, you should register only the digit of the ten, so the division by 10, and finally make an arithmetic sum for this found ten. I chose all the same with the ten of 3 so I could have something to add 3+2+1 to, so Dec. It does not return to the screen, because I use seeReturn.sh to see the result of the operation. Yes, he seems to have done nothing, but the idea is to operate values, vectors and addresses.
in terminal use nasm -f elf -o nomedoarquivo.o nomedoarquivo.asm
to compile and ld -m elf_i386 -s -o nomedoarquivo nomedoarquivo.o
to the Linker.
UPDATING THE QUESTION: has any way of traversing the vector from the first position without setting pointer? I tried offset array but gave syntax error too.
What would be your goal with this program? it has some accounts, but does not do any I/O operation - so even if it works, it will end without looking like it did anything.
– jsbueno
another - it’s for Windows/DOS right? I vaguely remember the int 80h with code "1" to end the program. Need to mark, because on Mac and Linux would be different.
– jsbueno
the goal is to make a sequence of actions: first go through the vector of 20 positions and find the lowest value by updating the register. When you finish going through the vector, you should register only the digit of the ten, so the division by 10, and finally make an arithmetic sum for this found ten. I chose all the same with the ten of 3 so I could have something to add 3+2+1 to, so Dec. It does not return to the screen, because I use seeReturn.sh to see the result of the operation. Yes, he seems to have done nothing, but the idea is to operate values, vectors and addresses.
– Cibele Montibeller
It’s for linux, but in the slides I took from some lessons on the internet, in Ubuntu people use this mov eax,1 - int 80h as a system call.
– Cibele Montibeller
in the terminal use nasm -f Elf -o filename. the filename.asm to compile and Ld -m elf_i386 -s -o filename filename filename. o for Linker. Therefore global _start.
– Cibele Montibeller