Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:06:14+00:00 2026-05-29T16:06:14+00:00

I have written the following code, can you explain me what does the assembly

  • 0

I have written the following code, can you explain me what does the assembly tell here.

typedef struct
{
    int abcd[5];
} hh;

void main()
{
    printf("%d", ((hh*)0)+1);
}  

Assembly:

        .file   "aa.c"
        .section        ".rodata"
        .align 8
.LLC0:

        .asciz  "%d\n"
        .section        ".text"
        .align 4
        .global main
        .type   main, #function
        .proc   020
main:

        save    %sp, -112, %sp
        sethi   %hi(.LLC0), %g1
        or      %g1, %lo(.LLC0), %o0
        mov     20, %o1
        call    printf, 0
         nop
        return  %i7+8
         nop
        .size   main, .-main
        .ident  "GCC: (GNU) 4.2.1"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:06:15+00:00Added an answer on May 29, 2026 at 4:06 pm

    Oh wow, SPARC assembly language, I haven’t seen that in years.

    I guess we go line by line? I’m going to skip some of the uninteresting boilerplate.

            .section        ".rodata"
            .align 8
    .LLC0:
            .asciz  "%d\n"
    

    This is the string constant you used in printf (so obvious, I know!) The important things to notice are that it’s in the .rodata section (sections are divisions of the eventual executable image; this one is for “read-only data” and will in fact be immutable at runtime) and that it’s been given the label .LLC0. Labels that begin with a dot are private to the object file. Later, the compiler will refer to that label when it wants to load the address of the string constant.

            .section        ".text"
            .align 4
            .global main
            .type   main, #function
            .proc   020
    main:
    

    .text is the section for actual machine code. This is the boilerplate header for defining the global function named main, which at the assembly level is no different from any other function (in C — not necessarily so in C++). I don’t remember what .proc 020 does.

            save    %sp, -112, %sp
    

    Save the previous register window and adjust the stack pointer downward. If you don’t know what a register window is, you need to read the architecture manual: http://sparc.org/wp-content/uploads/2014/01/v8.pdf.gz. (V8 is the last 32-bit iteration of SPARC, V9 is the first 64-bit one. This appears to be 32-bit code.)

            sethi   %hi(.LLC0), %g1
            or      %g1, %lo(.LLC0), %o0
    

    This two-instruction sequence has the net effect of loading the address .LLC0 (that’s your string constant) into register %o0, which is the first outgoing argument register. (The arguments to this function are in the incoming argument registers.)

            mov     20, %o1
    

    Load the immediate constant 100 into %o1, the second outgoing argument register. This is the value computed by ((foo *)0)+1. It’s 20 because your struct foo is 20 bytes long (five 4-byte ints) and you asked for the second one within the array starting at address zero.

    Incidentally, computing an offset from a pointer is only well-defined in C when there is actually a sufficiently large array at the address of the base pointer; ((foo *)0) is a null pointer, so there isn’t an array there, so the expression ((foo *)0)+1 technically has undefined behavior. GCC 4.2.1, targeting hosted SPARC, happens to have interpreted it as “pretend there is an arbitrarily large array of foos at address zero and compute the expected offset for array member 1″, but other (especially newer) compilers may do something completely different.

            call    printf, 0
            nop
    

    Call printf. I don’t remember what the zero is for. The call instruction has a delay slot (again, read the architecture manual) which is filled in with a do-nothing instruction, nop.

            return  %i7+8
            nop
    

    Jump to the address in register %i7 plus eight. This has the effect of returning from the current function.

    return also has a delay slot, which is filled in with another nop. There is supposed to be a restore instruction in this delay slot, matching the save at the top of the function, so that main‘s caller gets its register window back. I don’t know why it’s not there. Discussion in the comments talks about main possibly not needing to pop the register window, and/or your having declared main as void main() (which is not guaranteed to work with any C implementation, unless its documentation specifically says so, and is always bad style) … but pushing and not popping the register window is such a troublesome thing to do on a SPARC that I don’t find either explanation convincing. I might even call it a compiler bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have written the following code: As you can see there is a for
I have written the following code which works, but im wondering can I make
I have written the following code, but continually get a 'non-static method getText() can
I have written the following code: public class NewClass2 implements Comparator<Point> { public int
I have written a following code to get just the file name without extension
I have written the following code choice /m Do you want to add another
I have written the following code. But it is removing only &nbsp; not <br>
I have written the following IronPython code: import clr clr.AddReference(System.Drawing) from System import *
I have written my code in following way in cocos2d. id actionTo = [CCFadeOut
In physics library written in C# I have the following code: (in ContactManager.cs) public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.