Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does .byte mean in this asm line?

I am revisiting code that I wrote a while ago that does some math on large numbers. When I wrote the code, the lab had a few x86s that were split between 32 and 64 bits. My work was on UltraSPARCs, and I vaguely remember pulling this line of code from an Intel manual to be sure that the code was being used on a 64-bit CPU.

unsigned long x[4];
x[0] = 0;
x[1] = 0;
x[2] = 0;
x[3] = 0;
asm volatile(".byte 15;.byte 162" : "=a"(x[0]),"=b"(x[1]),"=c"(x[3]),"=d"(x[2]) : "0"(0) );

If x[0] was 0, all was well and the program started chugging away.

Can anyone explain to me what this line of code actually does?

like image 449
b degnan Avatar asked Feb 05 '16 17:02

b degnan


People also ask

What does .byte do in assembly?

"In addition to numeric operands, the BYTE directive allows character operands with a single character or string operands with many characters.

What does .fill do in assembly?

. FILL tells the assembler to set aside the next location in the program and initial- ize it with the value of the operand.

What does byte ptr do?

mov byte ptr [value_two],"e" : "Byte ptr" lets the assembler know you want to store a byte. This must be done, because value_two was declared as a word.


1 Answers

The bytes .byte 15 and .byte 162 represent the CPUID instruction.
When it executes you get results in EAX, EBX, ECX, and EDX.

These results will be stored in the array elements:

x[0] <- EAX
x[1] <- EBX
x[2] <- EDX
x[3] <- ECX
like image 155
Fifoernik Avatar answered Sep 24 '22 06:09

Fifoernik