Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with inline assembly using Xcode ide

Featured Replies

Posted

Being a beginner, I wasn't aware that you could even inline ASM into a c++ program until I checked out this keygen challenge and saw the keygen code written by Reaction: http://forum.tuts4yo...-1/page__st__20

I copied the asm portion of Reaction's code into Visual C++ and it compiled and ran fine. However, I'm trying to use the same code in Xcode on a Macbook Pro running OS X 10.6.8, and I'm getting some errors. I don't know if it's differences in syntax or maybe I need to define some things.

I'm attaching a screenshot of the errors with the code. Any help is appreciated!

post-60663-0-52932500-1342388147_thumb.p

I would seriously use Google to search for information first...

You are trying to paste MASM syntax assembler into X-Code, which from what i'm reading is GCC syntax, like trying to put Delphi code into Visual Basic.

http://www.ibiblio.o...mbly-HOWTO.html

Also, apparently there is a compiler switch to tell GCC to use intel syntax assembler, how effective though will be an exercise for you to find out:

.intel_syntax

http://www.reversing.be/article.php?story=20051203194931893

HR,

Ghandi

Edited by ghandi

  • Author

Thank you, I will read through that last link. Also, I only post questions when I'm "googled" out. In fact, I visited the HOW-To link you provided before I even posted my question. I'm still trying to understand as much of it as I can. It seemed to me, the more I read, that the syntax I was using would work on macs utilizing an intel chipset.

Also, the code would compile fine when I tried writing some simple assembly code like "xor eax,eax" and "mov al,bl". I only get the errors when trying to use things like "Dword ptr ds:[]".

I'll continue reading. Thanks again.

This is taken from the HOWTO website, it explains exactly what you are talking about:

3. GCC Assembler Syntax.

GCC, the GNU C Compiler for Linux, uses AT&T/UNIX assembly syntax. Here we’ll be using AT&T syntax for assembly coding. Don’t worry if you are not familiar with AT&T syntax, I will teach you. This is quite different from Intel syntax. I shall give the major differences.

  1. Source-Destination Ordering.
    The direction of the operands in AT&T syntax is opposite to that of Intel. In Intel syntax the first operand is the destination, and the second operand is the source whereas in AT&T syntax the first operand is the source and the second operand is the destination. ie, "Op-code dst src" in Intel syntax changes to "Op-code src dst" in AT&T syntax.
  2. Register Naming.
    Register names are prefixed by % ie, if eax is to be used, write %eax.
  3. Immediate Operand.
    AT&T immediate operands are preceded by ’$’. For static "C" variables also prefix a ’$’. In Intel syntax, for hexadecimal constants an ’h’ is suffixed, instead of that, here we prefix ’0x’ to the constant. So, for hexadecimals, we first see a ’$’, then ’0x’ and finally the constants.
  4. Operand Size.
    In AT&T syntax the size of memory operands is determined from the last character of the op-code name. Op-code suffixes of ’b’, ’w’, and ’l’ specify byte(8-bit), word(16-bit), and long(32-bit) memory references. Intel syntax accomplishes this by prefixing memory operands (not the op-codes) with ’byte ptr’, ’word ptr’, and ’dword ptr’. Thus, Intel "mov al, byte ptr foo" is "movb foo, %al" in AT&T syntax.
  5. Memory Operands.
    In Intel syntax the base register is enclosed in ’[’ and ’]’ where as in AT&T they change to ’(’ and ’)’. Additionally, in Intel syntax an indirect memory reference is like section:[base + index*scale + disp], which changes to section:disp(base, index, scale) in AT&T. One point to bear in mind is that, when a constant is used for disp/scale, ’$’ shouldn’t be prefixed.

Now we saw some of the major differences between Intel syntax and AT&T syntax. I’ve wrote only a few of them. For a complete information, refer to GNU Assembler documentations. Now we’ll look at some examples for better understanding.

+------------------------------+------------------------------------+
| Intel Code | AT&T Code |
+------------------------------+------------------------------------+
| mov eax,1 | movl $1,%eax |
| mov ebx,0ffh | movl $0xff,%ebx |
| int 80h | int $0x80 |
| mov ebx, eax | movl %eax, %ebx |
| mov eax,[ecx] | movl (%ecx),%eax |
| mov eax,[ebx+3] | movl 3(%ebx),%eax |
| mov eax,[ebx+20h] | movl 0x20(%ebx),%eax |
| add eax,[ebx+ecx*2h] | addl (%ebx,%ecx,0x2),%eax |
| lea eax,[ebx+ecx] | leal (%ebx,%ecx),%eax |
| sub eax,[ebx+ecx*4h-20h] | subl -0x20(%ebx,%ecx,0x4),%eax |
+------------------------------+------------------------------------+

HR,

Ghandi

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.