2009-04-05 8 views
4

I "Portierung" eine NASM Quelle GAS bin, und ich fand die folgenden Codezeilen:Wie übersetzt NASM "Push-Byte" in GAS-Syntax?

push byte 0 
push byte 37 

GAS nicht "Push-Byte" oder "pushb" erlaubt.

Wie soll ich den obigen Code zu GAS Syntax übersetzen?

Dank

+0

In Verbindung stehend: http://stackoverflow.com/questions/2586591/why-is-it-not-possible-to-push-a-byte-onto-a-stack-on-pentium-ia-32 –

Antwort

5

pushb wurde von GAS entfernt. Sie sollten den Befehl push verwenden können, um den gleichen Effekt zu erhalten. Ein wenig mehr Informationen ist here.

1

1)push byte in NASM 2.11 64-Bit kompiliert auf die gleiche wie nur push, mit der Ausnahme, dass es sich weigert, zu kompilieren, wenn das Ding geschoben größer als ein Byte:

push 0x0000 
push 0x01 
push 0x0001 
push 0x10 

ist das gleiche wie:

push byte 0x0000 
push byte 0x01 
push byte 0x0001 
push byte 0x10 

Aber die folgenden fehlschlagen:

push byte 0x0100 
push byte 0x1000 
push byte 0x01000000 
push byte 0x10000000 

Alle diese kompilieren zu der 6a XX Form der Anweisung.

2) NASM und GAS entscheiden automatisch, welche Form von der Größe Operanden basiert zu verwenden:

Die GAS 2.25:

push $0x0000 
push $0x01 
push $0x0001 
push $0x10 
push $0x0100 
push $0x1000 
push $0x01000000 
push $0x10000000 

Kompiliert auf die gleiche wie die NASM:

push 0x0000 
push 0x01 
push 0x0001 
push 0x10 
push 0x0100 
push 0x1000 
push 0x01000000 
push 0x10000000 

objdump:

0: 6a 00     pushq $0x0 
    2: 6a 01     pushq $0x1 
    4: 6a 01     pushq $0x1 
    6: 6a 10     pushq $0x10 
    8: 68 00 01 00 00   pushq $0x100 
    d: 68 00 10 00 00   pushq $0x1000 
    12: 68 00 00 00 01   pushq $0x1000000 
    17: 68 00 00 00 10   pushq $0x10000000 

So nur push in GAS ist das gleiche wie push byte in NASM, aber ohne die Fehlerprüfung.

3) Der Modifikator, ist in GAS vorhanden ist w wie in:

pushw $0 

, die kompiliert:

0: 66 6a 00    pushw $0x0 

dh addiert das 0x66 Präfix 16 Bit umzuschalten Betrieb.

NASM Äquivalent ist:

push word 0 

4) Der Unterschied von mov ist, dass wir nicht willkürlich Druckgrößen steuern: sie alle drücken feste Beträge auf den Stapel sind.

Der einzige Parameter, den wir bei der Befehlskodierung steuern können, ist das Präfix 0x66 oder nicht.

Der Rest wird durch den Segmentdeskriptor bestimmt. Siehe Intel 64 and IA-32 Architectures Software Developer’s Manual - Volume 2 Instruction Set Reference - 325383-056US September 2015.