Assembly x86 question

Discussion in 'Mac Programming' started by richard4339, Feb 19, 2007.

  1. macrumors 6502a


    Sep 6, 2006
    Albiet, this isn't specifically for a Mac, its something I'm working on for an intro to assembly class. I'm working on a program to recursively generate fibonacci numbers, and here's what I have so far...

    TITLE Fibonacci
    ; Richard
    ; Feb 20, 2007
    .model small
    .stack 4096
    	array DWORD 30 DUP(0)
    main PROC
    	mov ax,@data
    	mov ds,ax
    	mov BX, OFFSET array
    	mov [bx],0
    	add bx, 4
    	mov [bx],1
    	sub bx,4
    	mov cx,0
    	call fib
    	mov ax, 4C00H ; setup
    	int 21H ; return to DOS
    	call WriteDec
    	call Crlf
    main ENDP
    fib PROC
    	mov dx,[bx]
    	mov cx,[bx+4]
    	add cx,dx
    	mov [bx+8],cx
    	add bx,4
    	cmp ax,30
    	jnz L1
    L1:	inc cx
    	call fib
    fib ENDP
    END main
    Its giving me all kinds of errors (if I do it in protected mode, it won't let me write to [bx], now its giving me errors everywhere, including there, and multiple other lines. Anybody have any suggestions or pointers?
  2. Moderator emeritus

    Jun 25, 2002
    Gone but not forgotten.
    It's been a while, so please forgive me for a stupid question but isn't the .386 directive incompatible with the .model small directive? Shouldn't it be forced to large or huge memory models in 386 mode, protected or otherwise?
  3. macrumors G5


    Nov 25, 2005
    1. The assembler in XCode uses "gas" (gnu assembler) syntax, which looks quite a bit different from what you have.

    2. Int 21 doesn't have one bit of a chance to run on a Macintosh. There is no DOS layer carefully hidden below MacOS X.
  4. thread starter macrumors 6502a


    Sep 6, 2006
    Our teacher is a Mac nut like myself, but the lab is a Windows lab, so we're using MASM for Windows to turn in for the assignments, which I've been unsuccessful in getting working on my MacBook Pro yet in Parellels or Bootcamp.

    As far as the .386 and the .model small, he has specifically told us to use those two directives, along with the int 21 to exit the program. I'm not actually sure how the int 21 will work on our machines at school either, though, since we definately do not have DOS on our machines...
  5. macrumors newbie

    Jan 19, 2007
    Are you building in the Mac or Windows environment? If you are doing assembly in Mac OS, for x86, you have natively incompatible code for sure because of the int 21.

    As far as bootcamp goes, I would not be suprised if Apple does not support the hidden DOS layer in windows that allows legacy code like that to be executed. Remember that Apple does not support the Windows 9x kernel through bootcamp; I suspect any legacy calls from XP are simply caught in a handler and the behavior is mimicked as need be.

    Try building it on a regular PC; if you still get errors let us know.
    Good luck.
  6. thread starter macrumors 6502a


    Sep 6, 2006
    Definite errors in boot camp; errors in Windows on lab machines as well. The errors I mentioned above actually were the ones from my lab machine.
  7. macrumors 68000


    Mar 6, 2003
    Calgary, Canada
    Step 1: Write and debug algorithm in C
    Step 2: Have the C compiler generate the assembly for you
    Step 3: Use that as a template for any assembler work you'll be doing
  8. macrumors 68000

    Feb 23, 2006
    Forgive me if I'm wrong, but I was under the impression that Boot Camp was just a drivers and EFI configuration, to allow you to run windows.

    It's the same hardware as any other PC laptop.
  9. Moderator emeritus

    Jun 25, 2002
    Gone but not forgotten.
    That's my impression, also, and that it emulates BIOS.

    Any DOS layer would be a part of Windows or not. The Windows NT (WinNT, Win2000, WinXP, Vista) base doesn't handle the DOS calls quite the same way that the graphical shells like Win98 do.
  10. macrumors 68030


    Sep 8, 2003
    Not quite, the firmware updates emulate the BIOS. Bootcamp (the app) is just a shiny CD burning utility and disk partitioner. No need to install it at all to get XP installed.

    This would be correct. Interrupts are setup by the OS, using BIOS. So when you use int 21, that call is rerouted using the BIOS interrupt table back into the OS. It used to be the quick way to call into the kernel, and int 21 worked on NT-based systems last time I wrote some assembler. It is the responsibility of the OS to setup the interrupt table.
  11. macrumors 68030


    Sep 8, 2003
    My comments and edits are inline. :)

    Now, my assembler is rusty, but this should at least point you in the right direction on a couple areas.
  12. macrumors 68000


    Dec 9, 2001
    State of Denial
    FFR, can someone share a link to an x86 assembly reference? I've never done any x86 work, so I don't know what's good and bad out there.

Share This Page