• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Assembly coding

RampantAndroid

Diamond Member
I've been trying to write some assembly programs up in linux using GCC...I'm unsure of how to start them off, so I just wrote a quick C file and compiled it to an assembly file and used that as a template...

This code below compiles fine, but gives segmentation faults....any help is appreciated!

Thanks!



.file "Lab8.s"
.version "1.00"

.section .rodata
.text
.align 4
.globl main
.type main,@function
main:
jmp .T1
A: .long 1
B: .long 255
.T1:
mov B,%eax
cmp %eax,A
JE .Done
dec %eax
mov %eax,B
jmp .T1
.Done:
jmp .T2
.T2:
leave
ret
.size main, .-main

 
Wild guess since I haven't done assembly coding since last century, but mixing variables into a code segment might only work for const data.

For writable variables you'd want the stack or a data segment, or to request a buffer from the OS (i.e. your own malloc()).
 
There is no C code for what I want to do...I'm trying to program in straight assembly. Yes, I know I could simply code it in C and then look at the assembly...but that's not my intent...my intent is to make clean looking assembly code.

As far as variables, I'm using the method GCC uses when I declare instance variables in C code...

What is GDB?
 
Originally posted by: RampantAndroid
There is no C code for what I want to do...I'm trying to program in straight assembly.

You fooled me with this line in the OP then...

I just wrote a quick C file and compiled it to an assembly file and used that as a template...

 
Originally posted by: tfinch2
Originally posted by: RampantAndroid
There is no C code for what I want to do...I'm trying to program in straight assembly.

You fooled me with this line in the OP then...

I just wrote a quick C file and compiled it to an assembly file and used that as a template...

Sorry...I'll explain my process then to help clear up:

I was unsure of what needed to be in the header, so I went an created a simple lab8.cc - it contained a basic program:

#include <iostream>
using namespace std;
int main()
{
int i = 0;
char strings[]="Hello World";
if(i==0)
cout << strings << endl << endl
return 0;
}


Looked at the assembly and so on.

I'll look about GDB...this is my school's linux box, is it installed by default (if not...I have my doubts that it is installed...)

Thanks!
 
In that example i (to the compiler) is const if it does any kind of optimization. So you might want to try altering the c code to change its value, to see if my earlier guess is correct.
 
Back
Top