Assembly and C

I'm trying to learn a little bit about assembly and such, so I made a multi-language program to figure out a little bit. It's very simplistic, but it accomplished what I want for the most part.
Here is what I wrote mix_asm.asm:
section .data
new_line db 0xa
nl_len equ $ - new_line
section .text
global print_str
print_str:
;prologue
push ebp
mov ebp,esp
push eax
push ebx
push ecx
push edx
mov ecx,[ebp+8]
push ecx
call str_length
mov edx,eax
mov ecx,[ebp+8]
mov ebx,1
mov eax,4
int 0x80
call print_nl
;epilogue
pop edx
pop ecx
pop ebx
pop eax
mov esp,ebp
pop ebp
ret
str_length:
;prologue
push ebp
mov ebp,esp
push ebx
push ecx
mov ecx,0
mov ebx,[ebp+8]
while_1:
cmp word [ebx+ecx],0x0
je while_1_end
add ecx,1
jmp while_1
while_1_end:
mov eax,ecx
;epilogue
pop ecx
pop ebx
mov esp,ebp
pop ebp
ret
print_nl:
;prologue
push ebp
mov ebp,esp
push eax
push ebx
push ecx
push edx
mov edx,nl_len
mov ecx,new_line
mov ebx,1
mov eax,4
int 0x80
;epilogue
pop edx
pop ecx
pop ebx
pop eax
mov esp,ebp
pop ebp
ret
and mix_c.c
/* test asm linking in c for *nix */
extern void print_str (char*);
int main ()
print_str( "Hello world!" );
return 0;
Now then, I can get it to work using elf format through nasm and linking with gcc. If I link with ld (ld -e main -o mix mix_asm.o mix_c.o) though, it returns with a segmentation fault. After executing through the end of the c:main function, it returns to address 0x1 (found using gdb), and I don't understand why. Is it something missing from the linker? A less pressing question, is there a way to get it to successfully link without using the elf format option in nasm? I'd greatly appreciate any help anyone can offer.

- First point to make: you do not need to save eax, ecx, edx, and esp in print_str.  Only ebx, esi, edi, and ebp need to be preserved.
- At while_1, you should be comparing the byte at [ebx+ecx] to 0, not the word.
You need the ELF option to nasm because otherwise it just produces `bin' format output, which won't link into an ELF executable.
And finally the reason it segfaults: ld with -emain treats main() as an entry point, which it actually isn't.  With main() as your entry point, when it hits the "return 0;", it will try to jump to whatever address is on the stack behind ebp, which is 0x1 for some reason.  GCC will correctly link in the default C runtime (crt{1,i,n}.o among others), which actually call the main() function, whereas ld won't.  gcc -v gives a good idea of how gcc is calling the linker.

Similar Messages

  • Document Assembly and Creation of Template Pages?

    What do “document assembly” and “creation of template pages” mean?
    I am a print graphic designer who usually handles the printing for a particular client who does long reports. I also give them a low resolution PDF for email circulation and posting on their website. They are now want to use the PDF for other purposes such as creating PowerPoint presentations that they will do in house. Therefore they have asked me to unlock all the security options -- that quite frankly I never even dealt with. Specifically they want to “allow document assembly, commenting, signing, and creation of template pages.” Assembly, commenting and signing seem innocuous, but will document assembly and template pages have significance for me as a graphic designer? I'm not sure what these two functions are.

    “document assembly” means the combination of documents.
    “creation of template pages” is for the creation of template pages for forms

  • I'm uploading a photobook I made to be published.  I need assistance in getting it to apple.  The book is assembled and gets to the end of uploading when I get an error message, an error occurred while uploading.  I have been trying all night.  Help!

    I'm uploading a photobook I made to be published.  I need assistance in getting it to apple.  The book is assembled and gets to the end of uploading when I get an error message, an error occurred while uploading.  I have been trying all night.  Help!

    Welcome to the Apple Community.
    I have seen previous versions mentioned in a pop up message before on iCloud.com, but I'm not really sure at all how it would help, as I couldn't get it to do anything.
    The best advice I have at this time is to back up your work on your iOS device by regularly saving it to iTunes, if anything goes wrong you can then either load it into the numbers app again on the device or recover it via iTunes on your computer.
    My syncs are immediate, I never get chance to see if it works in the background, sorry.

  • ALTER ASSEMBLY and Continuous Integration

    I have a small assembly of scalar SQL functions built in .NET that I've manually integrated to SQL Server with CREATE ASSEMBLY and then CREATE FUNCTION.  However, as part of my continuous integration and deploy process, I'd like to update the assembly
    with every build using ALTER ASSEMBLY.
    I've already taken care to guard against an unchanged MvID in the SQL batch I execute to do the update, but whenever a new build runs (and the MvID apparently changes), I get the following error:
    ALTER ASSEMBLY failed because the required method "Xxx" in type "Yyy" was not found with the same signature in the updated assembly.
    But the signature hasn't changed!  The signature is still just "DateTime? Yyy(DateTime?)".
    I've found very little information about this error in particular.  Any suggestions?

    I figured out what's the main reason in my case. In SQL Server 2008 R2, it is problem to have UDT with method that contains Nullable return or input parameters in it. For example if you have UDT and added one such method to it, then you do ALTER ASSEMBLY On
    SQL Server, assembly will deploy successfully, but the real issue comes when you will try deploy next version of your assembly, even if you don't touch that UDT and that method with Nullable param, you will get. 
    "ASSEMBLY failed because the required method "myfunction" in type  "myUDT" was not found
    with the same signature in the updated assembly." error
    for sure.
    I want to mention that I tested and this is not the case on Sql 2005 and Sql 2012

  • How to replace G4 ibook screen assembly and hinges

    My son dropped his iBook when it was open. The fall torqued the hinges so that the wires are showing, there's a quarter inch gap at the back, and the screen assembly has come away from the bottom of the screen. However, the LCD screen itself seems to be fine. I recently purchased on ebay a complete screen assembly with hinges that contains a dead LCD screen, and was wondering whether putting the undamaged screen in this used assembly and reconnecting it to the ibook is something I can do at home. If not, any idea what a repair shop would charge? Thanks!

    There may be an appropriate DIY guide to removing and replacing displays
    and other parts in the iBook online; keeping in mind if there is an AppleCare
    plan in effect, unauthorized repairs on non-covered repairs will likely void
    the remainder of the warranty on the rest of the computer.
    That said, places like this online have some guides which may help a user
    look into a computer no longer under any warranty. http://www.ifixit.com/Guide/Mac/
    Companies who specialize in repairing Apple portables
    and whose staff technicians are factory trained, can
    restore function to an Apple computer and often w/o
    interfering with any residual warranty on the rest of it.
    There are several, but I have experience with wegenermedia
    dot com in South Carolina, since they fixed an iBook of mine.
    Others are out there, and can be contacted directly by email.
    Wegenermedia has their own parts inventory; they would
    be able to help you get the computer together again.

  • Mixing Assembly and C/C++

    Greetings,
    This is my first post here! Anyway, I'm trying to get my hands dirty with SPARC assembly, but am having trouble calling routines written in assembly, and assembled with GAS from my C++ program. An explanation follows:
    I have the following routine in a .S file, which reads the SPARC performance counter:
    -- begin readtick.S --
    .global readtick
    .section ".text"
    .align 4
    readtick:     
         rd %tick, %o0
         srl %o0, %g0, %o1
         retl
         or %o0, %o1, %o0
    -- end readtick.S --
    Then, I have a simple C program, which I use to test the function:
    -- begin read_tick.c --
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/time.h>
    extern unsigned long long readtick (void);
    int
    main (int argc, char **argv)
         unsigned long long t0, t1;
         puts ("readtick");
         t0 = readtick();
         sleep(1);
         t1 = readtick();
         printf ("clock speed: %lu Hz\n", (t1 - t0));
         return 0;
    -- end read_tick.c --
    Then, to build I do the following:
    as -xarch=v8plus readtick.S -o readtick.o
    cc read_tick.c readtick.o -o read_tick
    This works fine, but if I move the code to a different, much larger C++ program, and build the relevant files the same way, I get the following message from the Debugger:
    Signal Caught:
    Signal received: SIGSEVG(11) with sigcode MAPERR(1)
    From process: 0
    For program pretendo, pid 15145
    ... and so on...
    trying to continue, I get the following message:
    (dbx) cont
    t@1 (l@1) signal SEGV (no mapping at the fault address) in (unknown) at 0x0
    0x00000000: <bad address 0x0>
    dbx: read of 4 bytes at address 0 failed -- Error 0
    Additionally, I tried calling an empty stub, which simply did
    retl
    nop
    and get the same results.
    Well that pretty much sums up the boat I'm in. Wondering if someone could perhaps shed some light on this for me. Any and all help would be kindly appreciated, and if I've left out any relevant infos, please let me know. Thanks.
    Eli Dayan

    I have the following routine in a .S file, which
    reads the SPARC performance counter:
    -- begin readtick.S --
    .global readtick
    .section ".text"
    .align 4
    readtick:     
         rd %tick, %o0
         srl %o0, %g0, %o1
         retl
         or %o0, %o1, %o0
    -- end readtick.S --I think you probably want something more like:
    readtick:
    rd %tick, %o1
    srlx %o1, 32, %o0
    retl
    srl %o1, 0, %o1
    For returning 64-bit values in 32-bit code,
    the high 32-bits goes in %o0,
    and the low 32-bits goes in %o1.
    I've zero-extended both 32-bit values,
    though I don't think that is strictly necessary.
    Then, I have a simple C program, which I use to test
    the function:
    -- begin read_tick.c --
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/time.h>
    extern unsigned long long readtick (void);
    int
    main (int argc, char **argv)
         unsigned long long t0, t1;
         puts ("readtick");
         t0 = readtick();
         sleep(1);
         t1 = readtick();
         printf ("clock speed: %lu Hz\n", (t1 - t0));
         return 0;
    -- end read_tick.c --You should use a "%llu" to print an "unsigned long long" value.
    Then, to build I do the following:
    as -xarch=v8plus readtick.S -o readtick.o
    cc read_tick.c readtick.o -o read_tick
    This works fine, but if I move the code to a
    different, much larger C++ program, and build the
    relevant files the same way, I get the following
    message from the Debugger:
    Signal Caught:
    Signal received: SIGSEVG(11) with sigcode MAPERR(1)
    From process: 0
    For program pretendo, pid 15145
    ... and so on...
    trying to continue, I get the following message:The segv is unlikely to be caused by the readtick function,
    unless you are trying to use its return value
    as an address or as an index without checking the range.
    You can ask dbx "where" and "regs",
    and possibly determine more about why it died.
    Additionally, I tried calling an empty stub, which
    simply did
    retl
    nop
    and get the same results.This seems like a further indication that the problem
    is not with the readtick, but with some other piece of code.
    Peter.
    -pd 7/25/05

  • Iphoto freezes at assembly and upload

    iphoto freezes at assembly and upload.

    Are you trying to purchase a book?  Is it an XL size book?  Boot into Safe Mode,  Mac OS X: Starting up in Safe Mode, and try creating a pdf preview file of the book.  If that succeeds you can then order and upload the book while in the Safe Mode.
    P.S:  Larry: congrats on Level 8.
    OT

  • Hp610-1115uk assembly and diss-assembly manual

    does anybody have a service manual and not just the user guides and getting started on user downloads area , but an service field book.  I want to correctly diss-assemble and upgrade cpu .
    thanks again for all posts really appreciated

    You should perhaps post this in the Unix forum instead.
    http://discussions.apple.com/forum.jspa?forumID=735
    Does the documentation for ALD say it is supposed to work on OS X?
    I suppose you have seen this one?
    http://www.zathras.de/angelweb/blog-debugging-assembler-on-macos-x.htm

  • SSRS - Pass Field Value List To Custom Function Assembly And Display Result

    I have written a SQL Server Reporting Services custom function as a C# assembly DLL and added it to my report. The purpose of the function is to search for outlier records in a collection of data. The data is represented as an array of floating point -tuplets
    (float[][]). In a medical patient database, these might be things such as blood pressure, cholesterol, hight, weight, waist measurement, etc.
    Several user input parameters are provided in the report, including numeric seed values for this particular algorithm. One multivalued parameter is a list of the numeric columns to be used as input to the algorithm because, importantly,
    the user can choose any subset of the value columns. I have a tablix that will display columns from the dataset conditionally, based on which of those columns are chosen.
    At this point, there are two issues I'm having difficulty with:
    How do I, in the course of running the report, take just the numeric columns that the user has chosen (ignoring all others in the dataset) and pass them as a float[][] to my custom function? Or is there something in the
    Microsoft.ReportingServices namespace that I should use to query an input dataset and convert it to an array in my C# code?
    How can I present the array subset returned by my custom function in a tablix in the report?
    Note: One thought that occurs to me is that outlier records tablix could be contained in a subreport, but I'm not clear on the logistics of passing dataset field results from a master report to a subreport.
    I envision a final report when run to be similar to the following:
    - Mark Z.

    Hi Mark,
    Sorry for the delay.
    From your description, you want to pass the dataset data to a custom code array, and return the subset of the array, right? In this case, you can use a custom function to add the data to array, and use the a custom function to sort the data base on your
    requirement and then use a function to get the subset of the array. Here are some sample custom code for your reference.
    Add to arryay
    Dim values As System.Collections.ArrayList=New System.Collections.ArrayList()
    Function SetText(ByVal value As Integer) As Integer
        values.Add(value)
        return value
    End Function
    Sort array
    Function Sort()
    Dim i as Integer
    Dim j as Integer
    Dim t as Integer
    Dim n as Integer=values.Count-1
    For i=n To 1 Step-1
     For j=0 To i-1
     if values(j)<values(j+1) Then
        t=values(j)
        values(j)=values(j+1)
        values(j+1)=t
     End if
     Next j
    Next i
    End Function
    Return value.
    Function Rank(ByVal value As Integer)
       return values(value)
    End Function
    Assume that you pass [Weight] field to array, you can use the expression below on the Weight column:
    =Code.SetText(Fields!Weight.Value)
    Then use the expression below to get the values.
    PatientID:=Sort() & Lookup(Code.Rank(0),Fields!Weight.Value,Fields.Patient.Value,"Dataset")
    Height:=Lookup(Code.Rank(0),Fields!Weight.Value,Fields.Height.Value,"Dataset")
    Weight:=Code.Rank(0)
    Hope this helps.
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Evaluating PDF Assembler and getting the following errors - Help needed

    I am having following three issues when merging document using PDF Assembler Service:-
    Error # 1 (JobID: 20369)
    System.ServiceModel.FaultException: Caused by: com.adobe.livecycle.assembler.client.ProcessingException: ALC-ASM-S00-002: Failed to execute the DDX - error messages provided. Caused by: com.adobe.internal.pdfm.assembly.AssemblyException: PDFM_S02013: The "insertDocument" operation failed on "137.pdf".; nested exception is:
    com.adobe.livecycle.assembler.client.ProcessingException: ALC-ASM-S00-002: Failed to execute the DDX - error messages provided.
    Error # 2 (JobID: 19966)
    System.ServiceModel.FaultException: Caused by: com.adobe.livecycle.assembler.client.ProcessingException: ALC-ASM-S00-002: Failed to execute the DDX - error messages provided. Caused by: com.adobe.internal.pdfm.assembly.AssemblyException: PDFM_S02013: The "insertDocument" operation failed on "1033.pdf".; nested exception is:
    com.adobe.livecycle.assembler.client.ProcessingException: ALC-ASM-S00-002: Failed to execute the DDX - error messages provided.
    Error # 3 (JobID: 19419)
    The request channel timed out while waiting for a reply after 00:09:59.9920000. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.

    "Illegal start of expression" and "} expected" usually mean that your brackets don't match. Indeed, your declaration of the main method is missing a '}':public static void main (String[] args)
    { // where's the '}' that goes with this one?this list of common compiler error messages and possible causes is a good resource: http://www.mindprod.com/jgloss/compileerrormessages.html

  • ES4 Assembler and portfolios' folders compatibility with Acrobat 9

    I have the following problem: I'm producing a PDF Portfolio with some nested file and folders through Assembler WebAPI.
    The portfolio is ok and works fine if opened with Acrobat XI, but the same portfolio is bugged if opened with Acrobat 9: all the package files are shown in the root directory and clicking (or right-clicking) on them causes a navigation to the (empty) directory specified in the DDX. There is also no way to open the package files.
    (PDF Portfolios created with Acrobat 9 works fine in both versions, so isn't a problem related to my installation of Acrobat 9)
    How can i make it works also in Acrobat 9? I'm defining a wrong DDX or it is a known bug?
    The file should be distributed to clients who use Acrobat 9 and cannot install newer version due to company policies.
    Example DDX (tried also many other forms, like using PDF source elements or defining a PackageFiles element with a file:/// source including subfolders, but the results in Acrobat 9 is always bugged):
    <DDX xmlns="http://ns.adobe.com/DDX/1.0/">
      <PDF result="output">
        <Portfolio>
          <Navigator source="MyNavigator" />
          <ColorScheme scheme="blueScheme" />
        </Portfolio>
        <Folder name="Folder1">
          <Folder name="Subfolder1">
            <PackageFiles source="source1.pdf" nameKey="source1.pdf">
              <File filename="source1.pdf" mimetype="application/pdf" />
            </PackageFiles>
            <PackageFiles source="source2.pdf" nameKey="source2.pdf">
              <File filename="source2.pdf" mimetype="application/pdf" />
            </PackageFiles>
          </Folder>
        </Folder>
      </PDF>
    </DDX>
    Thanks.

    I got the error msg translated:
    Cannot read input data, some characters cannot be showed/printed.
    I ran preflight and embedded the fonts and I'm hoping that fixes the problem.  I haev no way of testing this.  Does anyone know if I did the right thing or is there something else I should do?

  • Components, assemblies and geography.

    This is my story.
    I bought a MacBook Pro 15" Hi-Res and hard disk running at 7200 RPM. In AppleStore I was told that since the setting was not the standard, the computer would assemble at different locations.
    The MacBook Pro arrived and the hard disk had problems (vibration and noise, it was a Seagate). I observed in detail all the components and this was the only "relevant" issue. Screen showed slight deterioration of brightnes at the bottom, but I had read somewhere that it could be something "normal" in the Hi-Res panels. However, based on the vibration of the HD, AppleCare, with kindness, suggested a replacement.
    Came the second computer and tried it for a few days. Observed in detail its operation and caught my attention one thing: the brightness of the screen was perfectly distributed. On the hard disk, it (a Hitachi) operated much quieter than the previous one, but issued an uncomfortable noise, which was noticeable in quiet spaces. I posted my question in this forum on the topic: http://discussions.apple.com/click.jspa?searchID=-1&messageID=12425759. I checked in After Sales Service and suggested replacement.
    However, before requesting a replacement I consulted the model of the screen, thinking ask for the same for the new MacBook Pro. It was a Samsung LTN154MT07.
    I made the request and pledged to maintain the same panel (in detail and not only as a general specification of 15" Hi-Res screen). However, I checked today with After Sales and never made the record of this specific request.
    On pending the arrival of the computer, the question is as follows.
    Reviewing some forums (e.g. http://forums.macrumors.com/showthread.php?t=914054), there has been some problems in the distribution of brightness in LG Phillips (LP154WE3-TLB1) panels, transmitting a better experience Samsung models (LTN154MT07). It is a hypothesis, but perhaps the first computer that came had a LG Phillips panel (did not seek to model.)
    By tracking purchases that facilitates Apple Store, the route that made assembling the first MacBook Pro (with Seagate disk and perhaps LG Phillips panel) was:
    Shanghai (CN), Cologne (DE), Incheon (KR), Almaty (KZ), Warsaw (PL), Cologne (DE), Spain.
    And the second MacBook Pro (with a Hitachi hard disk and Samsung panel) was:
    Shanghai (CN), Cologne (DE), Dubai (AE), Cologne (DE), Spain.
    The current route is still similar to the first MacBook Pro.
    If the assembly depends on the components manufactured at each location, I can assume that the (third) MacBook Pro will possess an LG Phillips panel and/or a Seagate hard disk (both aspects makes the computer's configuration is not "normal" and merit, perhaps, the assembly.)
    I know this description may be very detailed and perhaps unnecessary, but I want to know if anyone has had similar experience from the course of assembling his/her MacBook Pro and the quality or brand of components.
    Thank you very much.

    Jorge: Your computers have all been completely assembled in the same place — Shanghai — before being shipped anywhere. The routes they take to reach you have nothing at all to do with their assembly or with the components used in them, but are determined entirely by the shipper.
    You cannot specify any of the components to be used in a configured-to-order Mac in greater detail than you see offered on the Apple Store website. If you were told otherwise, you were misinformed.

  • Assembled and Imported to Test System but no changes made!!

    Hi,
          I am unable to find why the changes are not reflected in Test System. From last 2 days i am working on this still no clue...
    Process I followed:
    imported from Consolidation tab, next assembled all the SCA files which includes dependencies and its successfully assembled, next in Test tab imported all the SCA files, but i am not able to see the changes.
    Any help highly appreciated
    Regards,
    Ayesha.

    Yes Ayesha bcozz i faced the same problem in my previous assignment.
    Do this:
                  First assemble the components which are showing the status "waiting for assembly" , next assemble the main SCA file which consists of all the changed source even the status of the SCA is "Assemble".
    After assembling the SCA files in Assemble tab go to test tab, here try to import the files which you have assembled in previous step.
    This will solve your issue. try and let me know the result.
    Regards,
    Anil.

  • Non configurable Assembly and Configurable Assembly

    Hi
    Can somebody correct my understanding of these two concepts.
    Non Configurable Assembly: The header material will have child components but it is not activated for configuration.
    Configurable Assembly: The header material will have child components and over above these the header item is also elgible to be configurable.
    Kind Regards
    Chakradhar

    In the standard R/3 System, the following item category groups determine which item categories are assigned to configurable materials in the sales order:
    · Item category group 0002
    Pricing and transfer of requirements for header material
    · Item category group 0004
    Pricing and transfer of requirements for components
    The BOM of the configurable material may contain configurable assemblies, which are copied to the sales order as subordinate items. The item category group of the materials and the item category of the superior material determine the item category of these subordinate items.
    Source--->Sap library
    http://help.sap.com/saphelp_46c/helpdata/en/92/58bfc6417011d189ec0000e81ddfac/frameset.htm

  • After I order a calendar, it is assembled and it keeps asking me to update my account information. I have done so 5x, but then it never finishes and tells me it has been ordered. I am using iPhoto 9.

    When I attempt to purchase a calendar, it is assembled. Then it keeps asking me to update my account information. I have done so 5x and said ok, but then it never finishes and tells me the calendar has been ordered. I am using iPhoto 9.

    and did you
    Go to your account in the Apple store (store.apple.com) and re-enter all of your information,
    LN

Maybe you are looking for