當前位置:首頁 » 編程語言 » c語言變數轉匯編
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言變數轉匯編

發布時間: 2022-04-27 19:55:10

⑴ 幫我把c語言轉成匯編語言

給你一個匯編實現strcmp函數的代碼,具體如何初始化寄存器就自己寫吧,如有幫助謝謝採納

int zhh_strcmp(const char *src, const char * dest)
{
int result=0; //定義臨時變數用於保存返回結果
__asm //內聯匯編開始
{
mov esi,src //將源字元串放入ds:esi
mov edi,dest //將目標字元串放入es:edi
START: //開始
lodsb //將ds:esi的第一個位元組裝入寄存器AL,同時[esi]+1
scasb //將es:edi的第一個位元組和AL相減,同時[edi]+1
//cmpsb 將edi 和 esi的位元組相減
jne NOTEQ //不相等,轉到NOTEQ處理

test al,al //看看AL是否為NULL
jne START //不為空,則比較下一個
xor eax,eax //為空,將寄存器EAX清空為0
jmp ENDCMP //跳轉到返回結果的地方
NOTEQ: //不相等
mov eax,1 //不相等時的處理,將EAX置1
jl ENDCMP //如果是大於的話,跳到返回結果的地方
neg eax //將EAX取反,變為-1

ENDCMP: mov result,eax //結果存入result

}

return result; //返回

}

⑵ C語言轉換成匯編語言

win-tc
可以將C代碼編譯為匯編代碼。
在「運行」,「編譯配置」里選取中編譯目標為匯編文件。
另外,將其它語言編譯為匯編代碼不叫「
反匯編
」。

⑶ 如何將C語言代碼轉換為對應的匯編代碼

VC6.0下有兩種方法:
(1)增加參數/FA:Project->Setting...,C/C++選項卡中的Project Options中增加參數/FA,編譯後debug目錄中將會增加對應源文件的匯編文件(*.asm)。
(2)如果想查看C語句對應的匯編代碼的話,可以這樣:F11單步調試,在debug工具欄中選擇「disassembly」即可。每行C代碼下面就是對應的匯編代碼。
如果debug工具欄不見了,可在VC上方空白菜單處右鍵,選擇「debug」即可彈出debug工具欄。

例如:
C代碼程序:
int main()
{
int a = 3;
int b = 4;
int c = a + b;
printf("c=%d/n", c);

return 0;
}

對應的匯編代碼程序(部分)如下:
5: int a = 3;
00401028 mov dword ptr [ebp-4],3
6: int b = 4;
0040102F mov dword ptr [ebp-8],4
7: int c = a + b;
00401036 mov eax,dword ptr [ebp-4]
00401039 add eax,dword ptr [ebp-8]
0040103C mov dword ptr [ebp-0Ch],eax

gcc下編譯加參數-S,如gcc a.c -S,編譯後會自動生成匯編文件a.asm。

⑷ C語言轉匯編問題

當然可以
不過c語言生成的程序,局部變數段地址在ss裡面,全局變數段地址在ds裡面。
讀寫數據需要確定數據的段地址和偏移地址。

對於段地址。 若int a=500是局部變數,那麼寫入的時候需要保存段寄存器裡面的值是ss。是全部變數則保證段寄存器裡面的值是ds。
對於偏移地址,c語言可以用&a這樣的方式獲得。

全局變數的寫法大致是如下代碼
mov bx, &a
mov wrod ptr ds:[bx], 500

⑸ 如何將c語言變成匯編

理論上來說C語言改成匯編是完全可以的,當然實際上還是有一定難度。

1、完全手工根據C語言的流程和目的,改編成匯編語言,這樣做工作量很大

2、利用模擬軟體,在模擬環境下,是有相應的匯編代碼的,這樣做工作量相對較小,但可讀性較差。

⑹ 51系列單片機混合編程時候 C語言定義的變數如何傳遞到匯編語言

可以強制對變數的地址進行固定,然後匯編操作相應的地址就行了

⑺ C語言轉換成匯編語言

這是用keil自動翻譯的,自己整理一下吧。
; FUNCTION delay05s (BEGIN)
;---- Variable 'i' assigned to Register 'R7'
0000 7F05 MOV R7,#05H
0002 ?C0001:
;---- Variable 'j' assigned to Register 'R6'
0002 7EC8 MOV R6,#0C8H
0004 ?C0004:
;---- Variable 'k' assigned to Register 'R5'
0004 7DFA MOV R5,#0FAH
0006 ?C0007:
0006 DDFE DJNZ R5,?C0007
0008 ?C0006:
0008 DEFA DJNZ R6,?C0004
000A ?C0003:
000A DFF6 DJNZ R7,?C0001
000C ?C0010:
000C 22 RET
; FUNCTION delay05s (END)

; FUNCTION main (BEGIN)
0000 ?C0011:
;---- Variable 'j' assigned to Register 'R4'
0000 7C01 MOV R4,#01H
;---- Variable 'i' assigned to Register 'R3'
0002 E4 CLR A
0003 FB MOV R3,A
0004 ?C0013:
0004 EC MOV A,R4
0005 F4 CPL A
0006 F590 MOV P1,A
0008 120000 R LCALL delay05s
000B EC MOV A,R4
000C 25E0 ADD A,ACC
000E FC MOV R4,A
000F 0B INC R3
0010 BB08F1 CJNE R3,#08H,?C0013
0013 ?C0014:
0013 7C80 MOV R4,#080H
0015 E4 CLR A
0016 FB MOV R3,A
0017 ?C0016:
0017 EB MOV A,R3
0018 C3 CLR C
0019 9408 SUBB A,#08H
001B 50E3 JNC ?C0011
001D EC MOV A,R4
001E F4 CPL A
001F F590 MOV P1,A
0021 120000 R LCALL delay05s
0024 EC MOV A,R4
0025 C3 CLR C
0026 13 RRC A
0027 FC MOV R4,A
0028 0B INC R3
0029 80EC SJMP ?C0016
; FUNCTION main (END)

⑻ 怎麼把C語言轉換成匯編

	.file	"Untitled1.c"
.text
.globl _factor
.def _factor; .scl 2; .type 32; .endef
_factor:
pushl %ebp
movl %esp,%ebp
pushl %edi
pushl %esi
pushl %ebx
subl $28,%esp
cmpl $1,8(%ebp)
jne L2
movl $1,%eax
movl $0,%edx
jmp L3
L2:
movl 8(%ebp),%eax
subl $1,%eax
movl %eax,(%esp)
call _factor
movl 8(%ebp),%ecx
movl %ecx,%ebx
sarl $31,%ebx
movl %edx,%edi
imull %ecx,%edi
movl %ebx,%esi
imull %eax,%esi
addl %edi,%esi
mull %ecx
leal (%esi,%edx),%ecx
movl %ecx,%edx
L3:
addl $28,%esp
popl %ebx
popl %esi
popl %edi
popl %ebp
ret
.globl _get_numerator
.def _get_numerator; .scl 2; .type 32; .endef
_get_numerator:
pushl %ebp
movl %esp,%ebp
subl $40,%esp
movl 8(%ebp),%eax
movl %eax,-16(%ebp)
movl 12(%ebp),%eax
movl %eax,-12(%ebp)
fildl 16(%ebp)
fstpl 8(%esp)
fldl -16(%ebp)
fstpl (%esp)
call _pow
leave
ret
.globl _get_denominator
.def _get_denominator; .scl 2; .type 32; .endef
_get_denominator:
pushl %ebp
movl %esp,%ebp
subl $24,%esp
movl 8(%ebp),%eax
movl %eax,(%esp)
call _factor
movl %eax,-16(%ebp)
movl %edx,-12(%ebp)
fildq -16(%ebp)
leave
ret
.globl _get_symbol
.def _get_symbol; .scl 2; .type 32; .endef
_get_symbol:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
andl $1,%eax
testl %eax,%eax
jne L9
movl $1,%eax
jmp L10
L9:
movl $-1,%eax
L10:
popl %ebp
ret
.def ___main; .scl 2; .type 32; .endef
.section.rdata,"dr"
LC2:
.ascii"pleaseinputthex:"
LC3:
.ascii"%lf"
LC6:
.ascii"sin(%lf)=%lf12"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp,%ebp
andl $-16,%esp
subl $96,%esp
call ___main
fldz
fstpl 80(%esp)
fldz
fstpl 72(%esp)
movl $LC2,(%esp)
call _puts
leal 56(%esp),%eax
movl %eax,4(%esp)
movl $LC3,(%esp)
call _scanf
fldl 56(%esp)
fldl LC4
fmulp %st,%st(1)
fldl LC5
fdivrp %st,%st(1)
fstpl 64(%esp)
movl $0,92(%esp)
jmp L12
L13:
fldl 80(%esp)
fstpl 72(%esp)
movl 92(%esp),%eax
addl %eax,%eax
addl $1,%eax
movl %eax,8(%esp)
fldl 64(%esp)
fstpl (%esp)
call _get_numerator
fstpl 32(%esp)
movl 92(%esp),%eax
addl %eax,%eax
addl $1,%eax
movl %eax,(%esp)
call _get_denominator
fdivrl 32(%esp)
fstpl 32(%esp)
movl 92(%esp),%eax
movl %eax,(%esp)
call _get_symbol
movl %eax,44(%esp)
fildl 44(%esp)
fmull 32(%esp)
fldl 80(%esp)
faddp %st,%st(1)
fstpl 80(%esp)
addl $1,92(%esp)
L12:
cmpl $3,92(%esp)
jle L13
fldl 56(%esp)
fldl 80(%esp)
fstpl 12(%esp)
fstpl 4(%esp)
movl $LC6,(%esp)
call _printf
movl $0,%eax
leave
ret
.section.rdata,"dr"
.align8
LC4:
.long -266631570
.long 1075388921
.align8
LC5:
.long 0
.long 1081507840
.ident "GCC:(tdm-2)4.8.1"
.def _pow; .scl 2; .type 32; .endef
.def _puts; .scl 2; .type 32; .endef
.def _scanf; .scl 2; .type 32; .endef
.def _printf; .scl 2; .type 32; .endef

⑼ C語言怎樣轉換成匯編語言

如果你用TC 那麼就是tcc -S -I(你的include文件夾) -L(你的lib文件夾) (你的文件)
例如,include在C:\tc\include lib在C:\tc\lib 要編譯文件hello.c
tcc -S -IC:\tc\include -LC:\tc\lib hello.c 會在當前目錄下生成一個hello.asm文件直接打開即可
(注意!!!-S -I -L 全都是大寫,區分大小寫)

如果你用gcc 那麼就是gcc -S (你的文件)
例如hello.c gcc -S hello.c
會在當前目錄下生成一個hello.S文件,直接用記事本打開不好看,最好用word打開(windows下的gcc,如果是linux直接vi hello.S 或 cat hello.S 或 less hello.S即可)
(注意!!!-S 是大寫,區分大小寫)

⑽ C語言怎麼轉換匯編程序

在單片機中,C語言轉換成匯編語言有一個小竅門,這要藉助於KEILC這個編譯軟體,步驟如下:

1、運行KEIL,建立工程,導入C語言。