有好心人来帮小朋友看个作业么?

2013-11-05 00:29:16 +08:00
 Livid
汇编我是完全不懂,大家帮看看他做的这个有没有什么问题吧,谢谢。



https://gist.github.com/anonymous/7305210
5099 次点击
所在节点    程序员
22 条回复
yangqi
2013-11-05 00:37:56 +08:00
貌似根本没有Loop起来啊,positive: 一次之后直接就结束了

那个endWhileLE最后jmp endif这个是跳到哪?
yangqi
2013-11-05 00:54:50 +08:00
汇编里面没有各种if, loop的statement, 只能通过各种jump来实现这些功能

loop的最后都要jmp回开始, 例如

whileLE: cmp eax, 0
...
...
jmp whileLE

另外如果positive, negative主要操作放到loop里面,如果你跳出来的话,positive最后还要再跳回去
orzfly
2013-11-05 00:55:50 +08:00
路过,话说 dec 1,eax 这是啥?难道不是 dec eax 或者 sub eax, 1 呢。
yangqi
2013-11-05 01:01:07 +08:00
@orzfly 恩,add那边也是一样,直接用inc就可以了
orzfly
2013-11-05 01:18:32 +08:00
另外我不会汇编,手头也找不到 VS 但是我按照题目想了想思路大概是这样求指点… @yangqi

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    char get1[] = "Please input an integer:";
    char get2[]="posamount:";
    char get3[]="negamount:";
    char get4[]="input n: ";
    char format[] = "%d";
    char format2[] = "%s%d\n";
    int input;
    asm{
        xor ebx, ebx
        xor ecx, ecx

        lea eax, get4
        push eax
        call printf
        add esp, 4

        lea eax, input
        push eax
        lea eax, format
        push eax
        call scanf
        add esp,8

        mov edx, input
    loop:
        cmp edx, 0
        jng endloop

        lea eax, get1
        push eax
        call printf
        add esp, 4

        lea eax,input
        push eax
        lea eax,format
        push eax
        call scanf
        add esp,8
       
        mov eax,input
        cmp eax,0
        jg positive
        je loop
        inc ecx
        jmp loop
       
    positive:
        inc ebx
        jmp loop
   
    endloop:
        push ebx
        lea eax, get2
        push eax
        lea eax, format2
        push eax
        call printf
        add esp, 12

        push ecx
        lea eax, get3
        push eax
        lea eax, format2
        push eax
        call printf
        add esp, 12

    }
    return 0;
}
yangqi
2013-11-05 01:27:31 +08:00
@orzfly 没看细节,只看了下大概的框架。貌似题目的意思是,positive就inc posamount, negative就inc negamount

所以loop里面的跳转还是有问题,还要加个和positive类似的negative分支

细节部分需要看下手册才能确定
pantaovay
2013-11-05 03:32:27 +08:00
是香港中文大学的吧?我记着两年前我同学也问过我同样的题目
hpowen
2013-11-05 03:50:57 +08:00
好无奈。。。。我这个还有这么多人问。。。。
然后善用搜索吧。。。
Air_Mu
2013-11-05 04:09:45 +08:00
以为是什么高难度小学题,春风得意的想进来卖弄下。当场就傻逼了
msg7086
2013-11-05 04:34:11 +08:00
直接扫字符串,遇到空格,有负号就加neg没负号就加pos
raptium
2013-11-05 07:55:10 +08:00
@pantaovay 应该不是,comp103 这种课号不像。中大课号是4个字母4个数字的,CS的课开头是 CSCI
Ultratude
2013-11-05 08:23:36 +08:00
这不算 cheating 么。
xdeng
2013-11-05 08:31:18 +08:00
@yangqi 伪指令
holy_sin
2013-11-05 09:19:48 +08:00
v2ex 水太深
Virgoer
2013-11-05 09:39:59 +08:00
@Air_Mu +1 。
iptux
2013-11-05 09:41:00 +08:00
大一之后就没碰过汇编。。。
sophy
2013-11-05 10:06:32 +08:00
@iptux 跟你一样
Todd_Leo
2013-11-05 12:08:41 +08:00
@raptium 泥好校友~
orzfly
2013-11-05 21:56:49 +08:00
https://gist.github.com/orzFly/7319335

@yangqi 研究了一天终于搞定了QAQ
orzfly
2013-11-05 21:58:32 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/88039

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX