CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old April 25th, 2005, 09:18 PM
    utcguy utcguy is offline
    Junior Member
     
    Join Date: Feb 2005
    Posts: 4
    utcguy is an unknown quantity at this point (<10)
    Question Assembly language on hypothetical machine

    given the following instruction set,

    A number of instructions are defined below:

    Opcode = Symbolic Representation = Meaning
    000 = LM A = Load AC from Memory Location A
    001 = SM A = Store AC to Memory Location A
    010 = SAC I = Set AC to an immediate number I
    011= BEZ I = If the Content of AC is Equal to Zero,
    Skip I instructions
    100 = J I = Unconditionally jump through I Instructions
    101 = AM A = Add to AC from Memory Location A


    I need to change this to convert C code into assembly code but I am unsure of how to add to this instruction set to handle array indexing, if possible, can anyone give me an idea of how to specify the index as a variable so that I would have access to the arrays? Thanks.

    Below is an example of what I mean:
    Code:
    C program: 
    
    int A=0;
    for(int i=0;i!=10;i++)
    	A=A+i;
    
    converts into this assembly program with the given instruction set:
    
    SAC 0
    SM 0 	#M[0]=0,A=0
    SM 1 	#M[1]=0, i=0
    SAC 1
    SM 2	#M[2]=1
    SAC -10
    SM 3	#M[3]= -10
    LM 1	#AC=i
    AM 3	#AC=AC-10, i=i-10
    BEZ	7	#if(AC==0) exit
    LM 1	# AC=i
    AM 0         # AC=AC+M[1], AC=i+A
    SM 0	#M[0]=AC
    LM 1	#AC=i
    AM 2 	#AC=AC+1 
    SM 1	# i=AC
    J -9
    Exit
    
    I need to convert:
    int B[10];
    B[0]=0;
    B[1]=1;
    Do{
    if(B[i]= = 0) B[i]=B[i+1]+3;
    else B[i]= -B[i];
    i=i++;
    }while(i!=10);
    
    into assembly code.
    Reply With Quote
      #2    
    Old April 27th, 2005, 01:01 AM
    Hobson's Avatar
    Hobson Hobson is offline
    Senior Member
     
    Join Date: Dec 2004
    Location: Poland
    Posts: 1,163
    Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)
    Re: Assembly language on hypothetical machine

    If I got all your rules right, when all operands at all instuctions MUST be immediate values, then it is not possible to implement indexing in this language. There should be at least one istruction which would allow to read or write memory using address stored either in acc or in other memory cell. So there should be instructions like:

    Load Acc with value stored at memory cell pointed by acc (or other memory cell)
    Store Acc at memory cell pointed by acc (or other memory cell)

    It would be enough if you could use
    LM ACC
    SM ACC
    but those are not said to be possible to use.

    With immeds only, it could be required to introduce instructions like
    LMP I: Load ACC with value stored at cell pointed by cell I
    SMP I: Store ACC at cell pointed by cell I
    You still have 2 opcodes free, you could use them for those.

    I hope that my ideas are right and that there is no mistake in this...

    PS as long as length of array is fixed and known at 'compile time', its possible to do without indexing, just separately for each cell, but I think that its not how you wand it to be done.

    Hob
    __________________
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:04 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009