low-level

What is INT 21h?

99封情书 提交于 2019-11-27 03:36:11
问题 Inspired by this question How can I force GDB to disassemble? I wondered about the INT 21h as a concept. Now, I have some very rusty knowledge of the internals, but not so many details. I remember that in C64 you had regular Interrupts and Non Maskable Interrupts, but my knowledge stops here. Could you please give me some clue ? Is it a DOS related strategy ? 回答1: From here: A multipurpose DOS interrupt used for various functions including reading the keyboard and writing to the console and

How are 3D arrays stored in C?

冷暖自知 提交于 2019-11-27 03:20:58
I understand that arrays in C are allocated in row-major order. Therefore, for a 2 x 3 array: 0 1 2 3 4 5 Is stored in memory as 0 1 2 3 4 5 However, what if I have a 2 x 3 x 2 array: 0 1 2 3 4 5 and 6 7 8 9 10 11 How are these stored in memory? Is just consecutive like: 0 1 2 3 4 5 6 7 8 9 10 11 Or is it some other way? Or does it depend on something? All "dimensions" are stored consecutively in memory. Consider int arr[4][100][20]; you can say that arr[1] and arr[2] (of type int[100][20] ) are contiguous or that arr[1][42] and arr[1][43] (of type int[20] ) are contiguous or that arr[1][42][7

Shifting a 32 bit integer by 32 bits

ⅰ亾dé卋堺 提交于 2019-11-26 23:17:47
问题 I'm slinging some C code and I need to bitshift a 32 bit int left 32 bits. When I run this code with the parameter n = 0, the shifting doesn't happen. int x = 0xFFFFFFFF; int y = x << (32 - n); Why doesn't this work? 回答1: Shift at your own peril. Per the standard, what you want to do is undefined behavior . C99 §6.5.7 3 - The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or

How do you set strings to uppercase / lowercase in Unicode?

柔情痞子 提交于 2019-11-26 23:08:08
问题 This is mostly a theoretical question I'm just very curious about. (I'm not trying to do this by coding it myself or anything, I'm not reinventing wheels.) My question is how the uppercase/lowercase table of equivalence works for Unicode. For example, if I had to do this in ASCII, I'd take a character, and if it falls withing the [a-z] range, I'd sum the difference between A and a. If it doesn't fall on that range, I'd have a small equivalence table for the 10 or so accented characters plus ñ

What is the best way to add two numbers without using the + operator?

本小妞迷上赌 提交于 2019-11-26 20:21:46
A friend and I are going back and forth with brain-teasers and I have no idea how to solve this one. My assumption is that it's possible with some bitwise operators, but not sure. CMS In C, with bitwise operators: #include<stdio.h> int add(int x, int y) { int a, b; do { a = x & y; b = x ^ y; x = a << 1; y = b; } while (a); return b; } int main( void ){ printf( "2 + 3 = %d", add(2,3)); return 0; } XOR ( x ^ y ) is addition without carry. (x & y) is the carry-out from each bit. (x & y) << 1 is the carry-in to each bit. The loop keeps adding the carries until the carry is zero for all bits. ackb

What is an “internal address” in Java?

雨燕双飞 提交于 2019-11-26 20:17:27
In the Javadoc for Object.hashCode() it states As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.) It's a common miconception this has something to do with the memory address but it doesn't as that can change without notice and the hashCode() does not and must not change for an object. @Neet Provided a link to a good answer https:/

Why doesn't Linux use the hardware context switch via the TSS?

眉间皱痕 提交于 2019-11-26 19:14:36
问题 I read the following statement: The x86 architecture includes a specific segment type called the Task State Segment (TSS), to store hardware contexts. Although Linux doesn't use hardware context switches, it is nonetheless forced to set up a TSS for each distinct CPU in the system. I am wondering: Why doesn't Linux use the hardware support for context switch? Isn't the hardware approach much faster than the software approach? Is there any OS which does take advantage of the hardware context

CPU Emulation and locking to a specific clock speed

倖福魔咒の 提交于 2019-11-26 19:09:54
问题 If you had read my other question, you'll know I've spent this weekend putting together a 6502 CPU emulator as a programming exercise. The CPU emulator is mostly complete, and seems to be fairly accurate from my limited testing, however it is running incredibly fast, and I want to throttle it down to the actual clock speed of the machine. My current test loop is this: // Just loop infinitely. while (1 == 1) { CPU.ClockCyclesBeforeNext--; if (CPU.ClockCyclesBeforeNext <= 0) { // Find out how

How are 3D arrays stored in C?

戏子无情 提交于 2019-11-26 10:26:58
问题 I understand that arrays in C are allocated in row-major order. Therefore, for a 2 x 3 array: 0 1 2 3 4 5 Is stored in memory as 0 1 2 3 4 5 However, what if I have a 2 x 3 x 2 array: 0 1 2 3 4 5 and 6 7 8 9 10 11 How are these stored in memory? Is just consecutive like: 0 1 2 3 4 5 6 7 8 9 10 11 Or is it some other way? Or does it depend on something? 回答1: All "dimensions" are stored consecutively in memory. Consider int arr[4][100][20]; you can say that arr[1] and arr[2] (of type int[100]

What is the best way to add two numbers without using the + operator?

六眼飞鱼酱① 提交于 2019-11-26 09:01:35
问题 A friend and I are going back and forth with brain-teasers and I have no idea how to solve this one. My assumption is that it\'s possible with some bitwise operators, but not sure. 回答1: In C, with bitwise operators: #include<stdio.h> int add(int x, int y) { int a, b; do { a = x & y; b = x ^ y; x = a << 1; y = b; } while (a); return b; } int main( void ){ printf( "2 + 3 = %d", add(2,3)); return 0; } XOR ( x ^ y ) is addition without carry. (x & y) is the carry-out from each bit. (x & y) << 1