2

アセンブリ言語の割り当てに対処しようとしています...

hello.c と world.asm の 2 つのファイルがあり、教授は gcc と nasm を使用して 2 つのファイルをコンパイルし、オブジェクト コードをリンクするように私たちに依頼します。

ネイティブのgccとnasmを使用して、64ビットのubuntu 12.10でうまく実行できます。

しかし、cygwin 1.7 を介して 64 ビット Win8 で同じことを試すと (最初に gcc を使用しようとしましたが、どういうわけか -m64 オプションが機能しません。教授が 64 ビットでコードを生成するように頼んだので、ググって見つけました-m64 を使用できるコンパイラ x86_64-w64-mingw32-gcc を含む mingw-w64 というパッケージ)、mainhello.o および world.o にコンパイルされたファイルを取得し、それらを main.out ファイルにリンクできます。しかし、どういうわけか、「./main.out」と入力して「Hello world」を待つと、何も起こらず、エラーメッセージも出力されません。

したがって、新しいユーザーは画像を投稿できません。申し訳ありませんが、Cygwin シェルで何が起こるかのスクリーンショットを次に示します。

ここに画像の説明を入力

私はすべての初心者です。ubuntuで割り当てを実行できることは知っていますが、ここで何が起こっているのか興味がありますか?

君たちありがとう

こんにちはC

//Purpose:  Demonstrate outputting integer data using the format specifiers of C.
//
//Compile this source file:     gcc -c -Wall -m64 -o mainhello.o     hello.c
//Link this object file with all other object files:  
//gcc -m64 -o main.out mainhello.o world.o
//Execute in 64-bit protected mode:  ./main.out
//

#include <stdio.h>
#include <stdint.h> //For C99 compatability

extern unsigned long int sayhello();

int main(int argc, char* argv[])
{unsigned long int result = -999;
 printf("%s\n\n","The main C program will now call the X86-64 subprogram.");
 result = sayhello();
 printf("%s\n","The subprogram has returned control to main.");
 printf("%s%lu\n","The return code is ",result);
 printf("%s\n","Bye");
 return result;
}

ワールド.asm

;Purpose:  Output the famous Hello World message.


;Assemble: nasm -f elf64 -l world.lis -o world.o world.asm


;===== Begin code area 

extern printf    ;This function will be linked into the executable by the linker

global sayhello

segment .data    ;Place initialized data in this segment

          welcome db "Hello World", 10, 0
          specifierforstringdata db "%s", 10,


segment .bss    

segment .text   

sayhello:        

;Output the famous message
mov qword rax, 0       
mov       rdi, specifierforstringdata
mov       rsi, welcome
call      printf

;Prepare to exit from this function
mov qword rax, 0                                  
ret;                                              

;===== End of function sayhello     
4

1 に答える 1

0
;Purpose:  Output the famous Hello World message.
;Assemble: nasm -f win64 -o world.o world.asm

;===== Begin code area

extern _printf    ;This function will be linked into the executable by the linker
global _sayhello

segment .data    ;Place initialized data in this segment
          welcome db "Hello World", 0
          specifierforstringdata db "%s", 10, 0

segment .text

_sayhello:
;Output the famous message
sub       rsp, 32 ; shadow space
mov       rcx, specifierforstringdata
mov       rdx, welcome
call      _printf
add       rsp, 32 ; clean up stack

;Prepare to exit from this function
mov qword rax, 0
ret

;===== End of function sayhello

質問の C ラッパーと一緒にリンクし、プレーンな cmd ウィンドウで実行すると、正常に動作します。

スクリーンショット

于 2013-01-21T15:07:48.633 に答える