asm的问题 [英] Problem with asm

查看:72
本文介绍了asm的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


我在汇编程序(NASM)中获得了以下代码,该代码打印出5。在

realmode:


mov ax,0xB800

mov es,ax

mov byte [ es:0],''5''


我现在想在gcc中做同样的事,但我被卡住了。 GCC不喜欢[es:0]

语法...


asm(" mov%ax,0xB800");

asm(" mov%es,%ax");

asm(" mov [%es:0],''5''"); < - 关于[的错误:-(


任何人都可以帮我解决这个问题吗?


或者我也可以直接在C中用指针做这个并且不要'在
全部使用asm()吗?我也无法让它工作......


感谢您的帮助!


Patrik

Hello!

I got the following Code in Assembler (NASM), which prints out "5" in
realmode:

mov ax, 0xB800
mov es, ax
mov byte [es:0], ''5''

I want to do the same in gcc now, but I''m stuck. GCC doesn''t like the [es:0]
syntax...

asm("mov %ax, 0xB800");
asm("mov %es, %ax");
asm("mov [%es:0], ''5''"); <-- Error about "[" :-(

Can anyone help me how to do this?

Or can I also do this directly in C with pointers and don''t use the asm() at
all? I couldn''t get this to work either...

Thanks for any help!

Patrik

推荐答案

Patrik Huber< pa ********* *@balcab.ch>潦草地写下以下内容:
Patrik Huber <pa**********@balcab.ch> scribbled the following:
Hello!
我在汇编程序(NASM)中获得了以下代码,它在
realmode中打印出5:
mov ax,0xB800
mov es,ax
mov byte [es:0],''5''
我现在想在gcc中做同样的事,但我'' GCC不喜欢[es:0]
语法...
asm(" mov%ax,0xB800");
asm(" mov%es ,%ax");
asm(" mov [%es:0],''5''");< - 关于" [&#; - (&b $ b Can)的错误有人帮我怎么做?


是什么让你想到一个关于a的问题ssembly语言有什么可以用C做
吗?为什么不在尝试使用Fortran或COBOL问题?

或者我也可以用C指针直接执行此操作并且不要使用asm()
所有?我无法让这个工作......
Hello! I got the following Code in Assembler (NASM), which prints out "5" in
realmode: mov ax, 0xB800
mov es, ax
mov byte [es:0], ''5'' I want to do the same in gcc now, but I''m stuck. GCC doesn''t like the [es:0]
syntax... asm("mov %ax, 0xB800");
asm("mov %es, %ax");
asm("mov [%es:0], ''5''"); <-- Error about "[" :-( Can anyone help me how to do this?
What makes you think a question about assembly language has anything to
do with C? Why not try Fortran or COBOL questions while you''re at it?
Or can I also do this directly in C with pointers and don''t use the asm() at
all? I couldn''t get this to work either...




尽我所能阅读你的汇编代码,我想你想做什么

这个...

char ** pp =(char **)0xB000;

** pp ='''5'';

这意味着在地址0xB000的地址存储对应于字符5

的字节值。


请注意,尽管如此,以上导致未定义的行为由

间接通过绝对地址。这可能适用于您的

平台,但它可能会导致您的程序出现段错误,或者更糟糕的是,在某些其他平台上,整个计算机都会崩溃。
< br $> b $ b -

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰-------- \

\-- http://www.helsinki.fi/~palaste ---------------------规则! -------- /



Trying my best to read your assembly code, I figure you want to do
this...
char **pp = (char**)0xB000;
**pp = ''5'';
Which means storing the byte value corresponding to the character ''5''
at the address located in the address 0xB000.

Be aware, though, that the above causes undefined behaviour by
indirecting through an absolute address. This might work on your
platform, but it might cause your program to segfault, or worse,
crash the entire computer, on some other platforms.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/


On Sun,2004年8月22日21:28:30 +0200,Patrik Huber

< pa ********** @ balcab.ch>在comp.lang.c中写道:
On Sun, 22 Aug 2004 21:28:30 +0200, "Patrik Huber"
<pa**********@balcab.ch> wrote in comp.lang.c:
你好!

我在汇编程序(NASM)中得到了以下代码,它打印出5。在
realmode:


为什么你认为你的问题属于comp.lang.c?大会

语言不是C.


[剪掉主题代码]

任何人都可以帮我怎么做?


是的,正确的新闻组中的人,几乎可以肯定是新闻:comp.lang.asm.x86。但你最好

指定你正在使用的操作系统。除非它像MS-DOS一样老旧,但大多数现代操作系统都不会让代码

工作,即使你可以建立它。

或者我也可以用C指针直接执行此操作,并且不要使用asm()吗?我无法让它工作......
Hello!

I got the following Code in Assembler (NASM), which prints out "5" in
realmode:
And why do you think your question belongs in comp.lang.c? Assembly
language is not C.

[snip off-topic code]
Can anyone help me how to do this?
Yes, the people in the proper newsgroup, which would be
news:comp.lang.asm.x86 almost certainly can. But you had better
specify what operating system you are using. Unless it is something
old like MS-DOS, most modern operating systems will not let that code
work even if you can get it to build.
Or can I also do this directly in C with pointers and don''t use the asm() at
all? I couldn''t get this to work either...




C允许分配任意地址,表示为整数

类型,指向具有适当强制转换的指针。结果是

实现定义。尝试使用指针读取或

写入是完全未定义的。所以你需要尝试组装

语言组。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答for

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt .comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html



C allows assigning an arbitrary address, represented as an integer
type, to a pointer with an appropriate cast. The result is
implementation-defined. Attempting to use the pointer to read or
write is completely undefined. So you need to try the assembly
language group.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


Jack Klein写道:


[snip]
Jack Klein wrote:

[snip]
或者我也可以用C指针直接执行此操作并且不要使用所有的asm()?我无法让它工作......
Or can I also do this directly in C with pointers and don''t use the asm() at
all? I couldn''t get this to work either...



C允许将一个任意地址(表示为整数
类型)分配给具有适当强制转换的指针。结果是实现定义的。尝试使用指针读取或写入是完全未定义的。所以你需要尝试组装
语言组。


C allows assigning an arbitrary address, represented as an integer
type, to a pointer with an appropriate cast. The result is
implementation-defined. Attempting to use the pointer to read or
write is completely undefined. So you need to try the assembly
language group.




它可能是未定义的,但我怀疑你使用的每个计算机系统

正在不断地这样做。


很难相信一些如此未定义的东西依赖于工作。

程序员必须是一个容易上当的人。 ;-)


我怀疑comp.arch.embedded或OS组中的人可以

给OP一个将他的程序转换为C的手(当然是未定义的!)


我同意它是实现定义的,但任何实现

没有做出合理的事情都会被视为破坏。


-Rich

-

Richard Pennington

电邮: ri ** @ pennware.com
http://www.pennware.com ftp://ftp.pennware.com



It may be undefined, but I suspect every computer system you use
is doing it constantly.

Hard to believe something so undefined is relied on to work.
Programmers must be a gullible lot. ;-)

I suspect the guys in comp.arch.embedded or an OS group could
give the OP a hand to convert his program to C (undefined, of course!)

I agree that it is implementation defined, but any implementation
that didn''t do something reasonable would be considered broken.

-Rich
--
Richard Pennington
Email: ri**@pennware.com
http://www.pennware.com ftp://ftp.pennware.com


这篇关于asm的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆