CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2011
    Posts
    38

    New to Assembly Language

    I have a problem...

    Write a program in assembly language to perform the following operation:

    C=A + B

    Consider A=7, B= 148 (hexadecimal)

    The origin of the program is 100 (hexadecimal)


    Would this be a Fortran program?
    If so, I had this...

    INTEGER A,B,C
    DATA A,7 B,148
    C=A+B
    END

    Is this correct?

  2. #2
    Join Date
    Nov 2011
    Posts
    38

    Re: New to Assembly Language

    Or would it be something like this...

    LDA AL
    ADD BL
    STA CL
    CLA
    CIL
    ADD AH
    ADD BH
    STA CH
    HLT

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: New to Assembly Language

    Quote Originally Posted by halt4814 View Post
    Or would it be something like this...

    [...]
    Depends on the architecture that's meant for, I'd say. To me that looks somewhat like 6502-style instructions, but with the 8086 register set or at least variables named like the 8086 registers.

    At the very least it's much closer than the one from post #1 which rather looks like BASIC.

    However, it doesn't declare or initalize the variables, neither does it account for the part of the assigment about the program origin.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    Nov 2011
    Posts
    38

    Re: New to Assembly Language

    So if I add ORG 100 to the top, then what?

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: New to Assembly Language

    Given the assembler that finally has to process that source code understands that directive and interprets integer literals as being hexadecimal by default (rather uncommon, IMO, at least without a directive telling it to do so), that would fix at least one of the potential problems I mentioned. However, without knowing more about your environment, I can't really say anything for sure.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Nov 2011
    Posts
    38

    Re: New to Assembly Language

    I do not think it needs to be double precision,so couldn't be as simple as...

    ORG 100
    LDA A
    ADD B
    STA C
    HLT
    A, 7
    B, 148

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: New to Assembly Language

    Your code seems to deal with integral numbers, and if that assumption is correct, the term double precision does not apply here, since it referts to floating point arithmetic.

    In case you're refering to the bitness (width) of integer operands in registers, now that doesn't match the model of the 8086 register set anymore: It has a 16-bit AX register, of which the high-order 8 bits can be accessed under the name AH and the low-order 8 bits can be accessed as AL. However, they're still no distinct registers: Modifying AL unconditionally modifies AX as well, for instance. Likewise for the registers BX, CX and DX. (There are more registers with properties differing from those, but I think we can ignore them here for now.)

    Again, it's quite important to know for which architecture you're writing your assembly language code. Assembly languages for different architectures can be quite different as well. And the more specific it gets, the more important that is.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured