G
G
Grigory Dikiy2016-04-24 19:57:52
C++ / C#
Grigory Dikiy, 2016-04-24 19:57:52

Segmentation error?

Good day, I am writing a code generator, but I ran into a problem, the fact is that when executing the underlying code, a segmentation error occurs .

print1:
  .string "%d\n"
.data
a:
  .long 0
.text
.global main
main:
  movl $-8, %ecx
  movl $-7, %edx
  cmp %ecx, %edx
  setg %ah
  push %ax
  pushl a
  pushl $print1
  call printf
  addl $8, %esp

  jmp label_01
label_00:

label_01:

  ret

And the second point, I want to add arithmetic to conditional expressions, that is, something like: 7 + 5 > 6 + 2 for arithmetic expressions I use the stack, but the problem is that the stack is also used to evaluate conditional expressions. Is it possible to somehow split the stack into parts? In the sense of referring to one part to evaluate arithmetic expressions, and to the other part to evaluate conditional expressions?
The third point, how can you implement work with real numbers in assembler, and are there appropriate registers for such cases?
PS The assembler code is generated automatically, so I know that it could be reduced, but so far this is not my main problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nirvimel, 2016-04-24
@frilix

The first point: The fact that a segmentation error occurs somewhere does not mean anything in itself. So the code is not analyzed (and even more so, generators are not written like that). It is necessary to consider this error under the debugger in detail: in what place, where the call came from, what is there with the stack, what is with the pointers. etc.
The second point: It is convenient to calculate the reverse Polish notation right on the top of the stack (but much faster still on registers, as long as there are enough registers). For everything else, local variables are allocated in the stack frame , for example (but still, registers should be used as much as possible here).
Third point: What is a coprocessor . Follow the links .
PS: Why not LLVM? Why another bike?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question