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 7186931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:44:10+00:00 2026-05-28T18:44:10+00:00

Let us assume the following CIL program: .assembly extern mscorlib {} .assembly Program {}

  • 0

Let us assume the following CIL program:

.assembly extern mscorlib {}
.assembly Program {}

.method private static void Main() cil managed
{
    .entrypoint
    .maxstack 4

    .locals init ( int32[] a,
               uint32   t )

    // Creates an array of int of size 10
    ldc.i4 10
    newarr int32
    stloc.0

    // Writes 0xaabbccdd at the index 2 of the array
    ldloc.0
    ldc.i4.2
    ldc.i4 0xaabbccdd
    stelem.i4

    // Loads
    ldloc.0
    ldc.i4 9 // <HERE>
    ldelem.i1

    stloc.1
    ldstr "Value: 0x{0:x8}"
    ldloc.1
    box [mscorlib]System.UInt32
    call void [mscorlib]System.Console::WriteLine(string, object)

    ret
}

This program:

  • creates an array of int size 10
  • writes 0xaabbccdd at index 2 of the array
  • tries to read one byte in the array using ldelem.i1
  • prints the result

The trick is that I use “ldelem.i1” instead of the more standard “idelem.i4” for performance issues (I want to avoid doing masking) The idea is to access to the data of the array the way one does with pointers in C.

But things are not so nice because the program crashes (IndexOutOfRangeException) for indexes of more than 10 as argument for ldelem.i1.
This males the trick useless as I can’t access data after the first half of the integer at the third index.

Ideally, I want to access bytes up to index 39, which corresponds to the last byte of the integer at index 9.

I would very much appreciate if somebody had some ideas on this point.

  • 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-28T18:44:12+00:00Added an answer on May 28, 2026 at 6:44 pm

    Interesting. The ECMA-335 states that it will throw an exception if the index is greater than or equal to the size of the array, which it definitely is. What surprises me about this isn’t that the exception is thrown, but that the index is treated as a byte index into an int array in the first place – I can’t see that that’s specified anywhere.

    I suspect you’re into the realms of unspecified behaviour, quite possibly behaviour which isn’t intended to be specified – I suspect you’re just not meant to use ldelem.i1 on an int array.

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

Sidebar

Related Questions

Let's assume I have the following code: public class MainClass { public static void
Let's assume we have the following method in the business layer. What's the best
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
let's assume we have the following code: public class TestScope { private int a
Let's assume I have a file named Main.java with the following code: public class
Let's assume we have the following structure: index.php config.inc.php \ lib \ lib \
Background: Let's assume I've got the following class: class Wrapped<T> : IDisposable { public
Let's assume the following: I have an IIS web site set up IIS is
I hope you can help... Let's assume I have following XML: <data> <token> <sessionId>12345</sessionId>
Let's assume that I have the following table: CREATE TABLE [dbo].[PricesHist] ( [Product] [varchar](6)

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.