麻烦写一个非常基本的SPARC汇编程序返回一个数字是奇数 [英] Trouble with writing a very basic SPARC Assembly routine that returns whether a number is odd

查看:195
本文介绍了麻烦写一个非常基本的SPARC汇编程序返回一个数字是奇数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写所谓ISODD小汇编程序,其中,顾名思义,返回如果传递的整数为奇数,通过从操作%1返回

I'm writing a small assembly routine called isOdd, which, as the name implies, returns if the passed integer is odd, by returning 1 from a % operation.

这是我的code迄今:

This is my code so far:

Function prototype: int isOdd( long num )

isOdd:
    save     %sp, -96, %sp  ! Save caller's window

    mov      %i0, %o0       ! Parameter num goes to %o0
    mov      2, %l0         ! 2 goes to local register
    call     .rem           ! Call modulus subroutine
    nop

    mov      %o0, %l0       ! moves the result of the subroutine 
                            ! to output register o0
    ret
    restore

不过,我没有得到良好的输出;事实上,好像是刚回来时,我传递给NUM任何值,而不是实际做模操作。

However, I don't get good output; in fact, it seems like it is just returning whatever value I pass to num, instead of actually doing the modulus operation.

谷歌还没有证明这样一个基本的问题很有帮助。这是我第一次集会code,所以我pretty陌生的概​​念寄存器,我认为把它们组合起来是我的错误可能说谎。

Google hasn't proved helpful for such a basic question. This is my first assembly code, so I'm pretty unfamiliar with the concept of "registers," and I think mixing them up is where my error may lie.

在此先感谢您的帮助!

推荐答案

有一大堆的寄存器,可以想到的是在块中
8.在任何一个时间,的8个寄存器三个连续块是作为可见
当前寄存器窗口,并标记为%O0 - %O7 %10 - 17%,和
%I0 - %的i7 。 (有8个寄存器第四块,%G0 - %G7 ,这是
全球而不是加窗结构的一部分。)

There are a whole bunch of registers, which you can think of as being in blocks of 8. At any one time, three consecutive blocks of 8 registers are visible as the current register window, and are labelled as %o0-%o7, %l0-%l7, and %i0-%i7. (There is a fourth block of 8 registers, %g0-%g7, which are global rather than being a part of the windowing arrangement.)

保存恢复,由8的两个的块在移动窗口该
重叠块允许参数和结果传递。寄存器
它被命名为%O0 - %O7 在调用者是同一那些被命名为
%I0 - %的i7 中被调用者。 (在被调用这两个新模块是 10% - 17%
这是私人的该窗口中本地使用,而%O0 - %O7 其中,
被叫方可以使用时,它反过来想调用另一个函数)。

When you save or restore, the window moves by two blocks of 8. The overlapping block allows for parameter and result passing. The registers which are named %o0-%o7 in the caller are the same ones that are named %i0-%i7 in the callee. (The two new blocks in the callee are %l0-%l7, which are private for local use within that window, and %o0-%o7 which the callee can use when it in turn wants to call another function.)

这是一个画面更加清晰:

It's clearer with a picture:

:                      :
+----------------------+
| Block of 8 registers |      caller's window
+----------------------+  +----------------------+
| Block of 8 registers |  |      %i0 - %i7       |    ---------.
+----------------------+  +----------------------+             | save
| Block of 8 registers |  |      %l0 - %l7       |             v
+----------------------+  +----------------------+  +----------------------+
| Block of 8 registers |  |      %o0 - %o7       |  |      %i0 - %i7       |
+----------------------+  +----------------------+  +----------------------+
| Block of 8 registers |              ^             |      %l0 - %l7       |
+----------------------+      restore |             +----------------------+
| Block of 8 registers |              `---------    |      %o0 - %o7       |
+----------------------+                            +----------------------+
| Block of 8 registers |                                callee's window
+----------------------+
:                      :

您来电者则以 NUM 参数为%O0 (在窗口),然后调用
您。您保存来建立一个新的窗口,所以你看到它在%I0 在你的
窗口。

Your caller places the num argument into %o0 (in its window), then calls you. You save to set up a new window, and so you see it in %i0 in your window.

.rem 有两个参数。你在你的%O0 01%(在这些地方你
窗口),然后调用它。它会看到他们在其%I0 %I1 (假设它确实
一个保存来建立一个新的窗口)。它把答案在%I0 ,这是
你的%O0

.rem takes two parameters. You place these in your %o0 and %o1 (in your window), then call it. It will see them in its %i0 and %i1 (assuming it does a save to set up a new window). It puts the answer in its %i0, which is your %o0.

同样,你应该把你的结果在你的%I0 ;谁叫你会看到它
在他们的%O0

Similarly, you should put your result in your %i0; whoever called you will see it in their %o0.

这篇关于麻烦写一个非常基本的SPARC汇编程序返回一个数字是奇数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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