Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Assembly On Mac
    primarykey
    data
    text
    <p>I'm using a MacBook Pro with an Intel Core 2 Duo processor at 2.53 GHz, but I was told Mac users must follow AT&amp;T syntax (which adds to my confusion since I am running Intel) and x86 (not sure what this means exactly).</p> <p>So I need to get into assembly but am finding it very hard to even begin. Searches online show assembly code that varies greatly in syntax and I can't find any resources that explain basic assembly how-tos. I keep reading about registers and a stack but don't understand how to look at this. Can anyone explain/point me in the right direction? Take, for example, this code which is the only code I found to work:</p> <pre><code>.data _mystring: .ascii "Hello World\n\0" #C expects strings to terminate with a 0. .text .globl _foo _foo: push %ebp mov %esp,%ebp pushl $_mystring call _myprint add $4,%esp pop %ebp ret </code></pre> <p>Very simple but what is it saying? I am having a confusing time understanding how this code does what it does. I know Java, PHP, and C, among other languages, but this, the steps and syntax of it, isn't clear to me. Here's the main file to go with it:</p> <pre><code>#include &lt;stdio.h&gt; void foo(); void myprint(char *s) {printf("%s", s);} main() {foo();} </code></pre> <p>Also, there's this which just multiplies numbers:</p> <pre><code>.data .globl _cntr _cntr: .long 0 .globl _prod _prod: .long 0 .globl _x _x: .long 0 .globl _y _y: .long 0 .globl _mask _mask: .long 1 .globl _multiply multiply: push %ebp mov %ebp,%esp mov $0,%eax mov _x,%ebx mov _y,%edx LOOP: cmp $0,%ebx je DONE mov %ebx,%ecx and $1,%ecx cmp $1,%ecx jne LOOPC add %edx,%eax LOOPC: shr $1,%ebx shl $1,%edx jmp LOOP DONE: pop %ebp ret </code></pre> <p>and the main.c to go with it:</p> <pre><code>#include &lt;stdio.h&gt; extern int multiply(); extern int x, y; int main() { x = 34; y = 47; printf("%d * %d = %d\n", x, y, multiply()); } </code></pre> <p>And finally three small questions:</p> <blockquote> <ol> <li><p>What is the difference between <code>.s</code> and <code>.h</code> file names (I have both a <code>main.c</code> and <code>main.h</code>, which one is for what)?</p></li> <li><p>And why does assembly need a <code>main.c</code> to go with it/how does it call it?</p></li> <li><p>Can anyone recommend a good assembly IDE like Eclipse is for Java or PHP</p></li> </ol> </blockquote> <p>Thanks to whomever answers (this is actually my first post on this site), I've been trying to figure this out for a few days and every resource I have read just doesn't explain the assembly logic to me. It says what <code>.data</code> or <code>.text</code> does but only someone who knows how to "think assembly" would understand what they mean? Also, if anyone is around New York City and feels very comfortable with Assembly and C I would love some private lessons. I feel there is a lot of potential with this language and would love to learn it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload