私はあなたの混乱を簡単に見ることができます。誰かが私を訂正しますが、これはAT & Tの構文です。私はそう思っています。そして、どのようにして "%"記号を入れ、括弧などを使用するかは、コンパイラライターが好きなように行うことができます。 (あなたがしたことが気に入らなければ、独自のコンパイラを書いて、それを無料で行うなど)。
私はこれをIntelの構文で書き直しました。私は彼らが何を呼んでいるのか正確に忘れていますが、とにかくその構文では目的地が命令の最初に来て、他の部分はそれに従います。レジスタ名のまわりの括弧は、「このレジスタが指し示すアドレスにあるものを見つける」ことを意味します。多くのレジスタを使用すると、独自のオフセットを追加することができ、チップにはそのオフセットが追加されたアドレスが生成されます。
私はこれが正しいと思いますが、今は本当に眠っているはずです。これはそのためにあまりにも多く
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Arun's Swap Via Xor Function ;
; ;
; Arun is studying C and ASM ;
; ;
; On Entry: var1 is at the 24th place in the stack ;
; ;
; var2 is at the 28th place in the stack ;
; ;
; Both of these are 32 bit numbers which ;
; is why they are 4 bytes apart ;
; ;
; On Exit: var1 is in Eax ;
; ;
; var2 is in Edx ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Aruns_Swap_Via_Xor_Function:
MovL Edx, [Esp + 24] ;var1 goes into Edx
MovL Eax, [Esp + 28] ;var2 goes into Eax
XorL Eax, Edx ;Xor them and put the result in Eax
MovL [Esp + 24], Eax ;Store the result in var1 on the stack
MovL Edx, [Esp + 28] ;Original var2 goes in Edx this time
MovL Eax, [Esp + 24] ;The bit fiddled var1 is now in Eax
;Be aware, this is not exactly optimized
; but it will work, and this compiler apparently
; doesn't want to take chances.
; The brass tacks are that this instruction
; as it appears here, is a defacto Nop
XorL Eax, Edx ;Now Xor both of those values and put the result in Eax
MovL [Esp + 28], Eax ;That modified value goes into var2
;(Be alert, this is really the original var1)
MovL Edx, [Esp + 24] ;The original var2 is now in Edx
MovL Eax, [Esp + 28] ;The modified var2 is now in Eax
XorL Eax, Edx ;Xor those two and put the result in Eax
;Now Eax and Edx hold each other's original contents
;
;(and life goes on)
を助けている場合
とにかく、参照してください。あなたがアセンブリ言語コースでこれに直面している場合に備えて、この問題は何年もの間(私を含む)人々を魅了してきました。あなたの教授がおそらく探しているものがあります。ちなみに、これはインターネット上で見つけることができます、ウィキペディア、実際には。
前の11個の命令は3つの命令を救助へ
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; A slightly optimized swap function ;
; ;
; Arun is studying C and ASM ;
; ;
; On Entry: var1 is in Eax ;
; ;
; var2 is in Ebx ;
; ;
; Both of these are 32 bit numbers, and ;
; so we will use 32 bit instructions. ;
; ;
; On Exit: var1 is in Ebx ;
; ;
; var2 is in Eax ;
; ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Slightly_Optimized_Swap_Routine:
XorL Eax, Ebx ;Xor them and put the result in Ebx
;At this point Eax is var1 and Ebx is weird number
XorL Ebx, Eax ;Xor that result with the origial var1
;At this point, Eax is var2 and Ebx is still weird number
XorL Eax, Ebx ;Xor them and put the result in Ebx
;At this point, Eax is var2 and Ebx is Var1
;
;(and life goes on)
最後に、ハードウェア設計者やマイクロプロセッサにすることができます...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; A slightly better optimized swap function ;
; ;
; Brought to you by Clint on Stack Overflow ;
; ;
; On Entry: var1 is in Eax ;
; ;
; var2 is in Ebx ;
; ;
; Both of these are 32 bit numbers, and ;
; so we will use 32 bit instructions. ;
; ;
; On Exit: var1 is in Ebx ;
; ;
; var2 is in Eax ;
; ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Slightly_Better_Swap_Routine:
XchgL Eax, Ebx ;Microprocessor magic, exchange them in one instruction.
; Honest, hardware guys can do stuff like that. The previous
; eleven instructions have been reduced to one. Ta-Da
;
;(and life goes on)
%esp(スタックポインタ)からのオフセット24/28バイト –
これらはesp(スタックポインタ)からのオフセットのように見えます。通常、スタックポインタからのオフセットを使用して、ローカル変数とパラメータにアクセスします。スタックは下向きに成長するので、負のオフセットを使用してパラメータにアクセスし、正のオフセットをローカル変数に使用します。 –
"XORを使用して2つの変数を交換するプログラムを作成します。"どうして?うまくいけば、アセンブリを検査するだけです。 –