ARM7打印/输出功能
我正在尝试实现一个简单的 Pascal 到 ARM 汇编编译器。我需要实现 write() 函数,但我不知道如何在汇编程序中实现它。我尝试用谷歌搜索但没有成功。我正在使用 Keil uVision 4 来模拟我的汇编代码。
假设我想编译以下程序:
PROGRAM myProg;
var A : integer;
BEGIN
A := 5;
write(A);
END.
它在 ARM 汇编中会是什么样子?
I am trying to implement a simple Pascal to ARM assembly compiler. I need to implement the write() function, but I have no idea how to to it in assembler. I tried to google it but without success. I am using Keil uVision 4 to emulate my assembly code.
Lets say I would like to compile the following program:
PROGRAM myProg;
var A : integer;
BEGIN
A := 5;
write(A);
END.
How would it look like in ARM assembly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用“free pascal”编译器尝试汇编器的外观,它支持多种 ARM 架构。
You can experiment with the "free pascal" compiler how the assembler looks like, it supports several ARM architectures.
Alex
这里有很多因素...可执行目标是什么?某种操作系统,还是原始硬件?如果它是一个操作系统,就会有一个 API 可供您使用,它应该代表您完成大部分繁重的工作。
但即便如此,这也只是故事的一半。 write() 背后是一个巨大的输出处理库,它知道如何将输入数据转换为有意义的输出 :: write() 是那些奇怪的过程之一,它采用可变数量的无类型参数,并以某种方式神奇地理解它们。
正如 Marco 所说,您可以查看 FP 的汇编程序输出,但我有一种感觉,您很快就会陷入无数的子例程调用中。
另一种选择可能是简单地把 Marco 的想法更进一步——你能不只使用 Free Pascal 吗?即使您的目标设备上没有操作系统,您仍然可以让它为您完成大部分工作。毫无疑问,您必须为 stdin 和 stdout 提供钩子,但除此之外 FP 可能是一个可行的答案?
Alex
There are so many factors here... what's the executable target? Some kind of operating system, or raw hardware? If it's an OS, there will be an API available to you, which should do most of the heavy lifting on your behalf.
But even then, that's only half the story. Behind write() is a huge output-handling library that knows how to convert input data into meaningful output :: write() is one of those odd procedures that takes a variable number of untyped parameters and somehow magically makes sense of them all.
As Marco said, you could have a look at FP's assembler output, but I have a feeling you'll get quickly bogged down in a myriad of subroutine calls.
The other option might be to simply take Marco's idea a bit further - can you not just USE Free Pascal? Even if you don't have an OS on the target device, you can still get it to do most of the work for you. You'd doubtless have to supply hooks to stdin and stdout, but other than that FP might be a workable answer?
write() 是操作系统的东西,而不是处理器指令的东西。操作系统需要数百到数十万条指令才能实现类似的功能,您必须以操作系统为目标或创建自己的操作系统,然后创建从处理器到该操作系统的接口,例如您可以选择使用swi指令进行系统调用。
如果您创建一个编译器来编译指令集、alu 操作、add、sub、xor 等、读写内存地址等,那么您将会有更好的运气。
现在您实际上是在问如何写入内存,而 A 是内存中的地址? (我的pascal很生疏)然后看看你的arm指令集,有几个/多个不同的指令,主要是你会想看看str指令,str,strh和strb(有些arm有strd)。因为这是你的 pascal 编译器,你可以让 write() 做任何你想做的事情,所以如果这就是你想要的,从 str 指令开始并从那里开始。
在我看来,你需要从开发你的arm汇编器开始,忘记pascal编译器……然后,制作一个pascal编译器来生成你知道如何使用和编写的汇编代码。如果您自己不知道如何在汇编程序中执行此操作,也不要让编译器执行此操作。
write() is an operating system thing not a processor instruction thing. it takes many hundreds to many hundreds of thousands of instructions for an operating system to implement something like that, you have to either target an operating system or create your own, then create an interface from the processor to that operating system, for example you might choose to use the swi instruction to make system calls.
You are going to have better luck to just create a compiler that compiles to the instruction set, alu operations, add, sub, xor, etc. read and write memory addresses, etc.
Now were you actually asking how to write memory and A is the address in memory? (my pascal is pretty rusty) then look at your arm instruction set, there are a few/number of different instructions, primarily you will want to look at the str instructions, str, strh, and strb (some arms have an strd). Since this is your pascal compiler you can make write() do whatever you want so if that is what you were intending start with the str instruction and go from there.
It sounds to me like you need to start by working on your arm assembler, forget about the pascal compiler...THEN, make a pascal compiler that produces assembler code that you do know how to use and write. If you dont know how to do it in assembler yourself dont let the compiler do it either.