小编kcm*_*ard的帖子

如何在 MIPS 中正确使用 mod 运算符?

在 MIPS 中,我对如何让 mod 工作感到困惑。下面是我到目前为止想出的代码。除了mod之外我可能还有更多错误,但我觉得这些错误是mod误解的结果。我要做的就是在此处获取工作代码(python):

i = 1
k = 0
while i < 9:
if i % 2 != 0:
    k = k + i
i += 1
print(k)
Run Code Online (Sandbox Code Playgroud)

正确转换为 MIPS。这是我第一次尝试组装,所以在下面的代码中可能有比 mod 错误更多的错误:

# Takes the odd integers from 1 to 9, adds them,
#  and spits out the result.
# main/driver starts here
    .globl main

main:

#data segment
.data

Li:     .byte 0x01  # i = 1
Lj:     .byte 0x09  # j = 9
Lk:     .byte 0x00  # k …
Run Code Online (Sandbox Code Playgroud)

python assembly mips modulo

5
推荐指数
1
解决办法
4万
查看次数

Go是否允许函数将另一个函数用作参数?

问题发生在Go代码的第17行.下面是python和Go中的程序,所以你可以看到我正在尝试做什么.Python工作,我的Go尝试都失败了.已经连续阅读了golang.org,谷歌也没有看到任何内容.

def my_filter(x):
  if x % 5 == 0:
    return True
  return False

#Function which returns a list of those numbers which satisfy the filter
def my_finc(Z, my_filter):

  a = []
  for x in Z:
    if my_filter(x) == True:
      a.append(x)
  return a

print(my_finc([10, 4, 5, 17, 25, 57, 335], my_filter))
Run Code Online (Sandbox Code Playgroud)

现在,Go版本我遇到了麻烦:

package main

import "fmt"

func Filter(a []int) bool {
    var z bool
    for i := 0; i < len(a); i++ {
        if a[i]%5 == 0 {
            z = true …
Run Code Online (Sandbox Code Playgroud)

parameters arguments nested function go

4
推荐指数
1
解决办法
103
查看次数

标签 统计

arguments ×1

assembly ×1

function ×1

go ×1

mips ×1

modulo ×1

nested ×1

parameters ×1

python ×1