RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
AccumPlus
Asked: 2020-12-29 17:47:14 +0000 UTC

C引导扇区编程

  • 10

我了解引导扇区编程。我是按照这篇文章做的。一切顺利,直到对输出“Hello, World!”进行编程为止。在C中。这是文章中给出的代码(实际上,我只是复制它):

__asm__(".code16\n");
__asm__("jmpl $0x0000, $main\n");

void printString(const char* pStr) {
     while(*pStr) {
          __asm__ __volatile__ (
               "int $0x10" : : "a"(0x0e00 | *pStr), "b"(0x0007)
          );
          ++pStr;
     }
}

void main() {
     printString("Hello, World");
}

我又按照那篇文章编译、链接等:

gcc -c -g -Os -m32 -ffreestanding -Wall -Werror test.c -o test.o
ld -melf_i386 -static -Ttest.ld -nostdlib --nmagic -o test.elf test.o
objcopy -O binary test.elf test.bin
dd if=/dev/zero of=floppy.img bs=512 count=2880
dd if=test.bin of=floppy.img

为了以防万一,我给出test.ld的内容:

ENTRY(main);
SECTIONS
{
    . = 0x7C00;
    .text : AT(0x7C00)
    {
        *(.text);
    }
    .sig : AT(0x7DFE)
    {
        SHORT(0xaa55);
    }
}

我运行 bochs,但我没有打印“Hello, World”,而是只得到一个“S”字符。

将函数移至 main:

__asm__(".code16\n");
__asm__("jmpl $0x0000, $main\n");
void main()
{
    char s[] = "Hello, World";
    char *str = s;
    while (*str)
    {
        __asm__ __volatile__ (
               "int $0x10" : : "a"(0x0e00 | *str), "b"(0x0007)
          );
        ++str;
    }
}

之后,他原则上不再展示任何东西。-Os 优化标志的异常有所帮助。结论是正确的。经过一些试验,我意识到这种优化“杀死”了循环。

然而,相同的代码,但移至一个函数,仍然输出“S”字符。

我寻求帮助解决这个问题。并且,如果可能的话,解释为什么优化标志“杀死”循环。谢谢!

更新。

来自 test.bin 的十六进制:

66 EA 3A 7C 00 00 00 00 66 55 66 89 E5 EB 19 67 66 8B 45 08 67 66 0F B6 00 66 0F BE C0 80 CC 0E CD 10 67 66 83 45 08 01 67 66 8B 45 08 67 66 0F B6 00 84 C0 75 D9 90 66 5D C3 66 55 66 89 E5 66 68 4F 7C 00 00 E8 C0 FF 66 83 C4 04 90 C9 C3 48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 00 14 00 00 00 00 00 00 00 01 7A 52 00 01 7C 08 01 1B 0C 04 04 88 01 00 00 1C 00 00 00 1C 00 00 00 8C FF FF FF 32 00 00 00 00 42 0E 08 85 02 43 0D 05 6C C5 0C 04 04 00 00 1C 00 00 00 3C 00 00 00 9E FF FF FF 15 00 00 00 00 42 0E 08 85 02 43 0D 05 4F C5 0C 04 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA

该文件是从以下来源获得的:

__asm__(".code16\n");
__asm__("jmpl $0x0000, $main\n");

void printString(const char* str)
{
    while (*str)
    {
        __asm__ __volatile__ (
               "int $0x10" : : "a"(0x0e00 | *str));
        ++str;
    }
}

void main()
{
    printString("Hello, World");
}

更新。

test.elf文件反汇编结果:

% objdump -d test.elf

test.elf:     file format elf32-i386

Disassembly of section .text:

00007c00 <printString-0x8>:
    7c00:   66 ea 3a 7c 00 00       ljmpw  $0x0,$0x7c3a
    ...

00007c08 <printString>:
    7c08:   66 55                   push   %bp
    7c0a:   66 89 e5                mov    %sp,%bp
    7c0d:   eb 19                   jmp    7c28 <printString+0x20>
    7c0f:   67 66 8b 45 08          mov    0x8(%di),%ax
    7c14:   67 66 0f b6 00          movzbw (%bx,%si),%ax
    7c19:   66 0f be c0             movsbw %al,%ax
    7c1d:   80 cc 0e                or     $0xe,%ah
    7c20:   cd 10                   int    $0x10
    7c22:   67 66 83 45 08 01       addw   $0x1,0x8(%di)
    7c28:   67 66 8b 45 08          mov    0x8(%di),%ax
    7c2d:   67 66 0f b6 00          movzbw (%bx,%si),%ax
    7c32:   84 c0                   test   %al,%al
    7c34:   75 d9                   jne    7c0f <printString+0x7>
    7c36:   90                      nop
    7c37:   66 5d                   pop    %bp
    7c39:   c3                      ret    

00007c3a <main>:
    7c3a:   66 55                   push   %bp
    7c3c:   66 89 e5                mov    %sp,%bp
    7c3f:   66 68 4f 7c             pushw  $0x7c4f
    7c43:   00 00                   add    %al,(%eax)
    7c45:   e8 c0 ff 66 83          call   83677c0a <main+0x8366ffd0>
    7c4a:   c4 04 90                les    (%eax,%edx,4),%eax
    7c4d:   c9                      leave  
    7c4e:   c3                      ret

更新。

这是处理器看到程序时对 hiew 的反汇编:

7c00: 66EA3A7C00000000              jmpf        00000:07C3A
7c08: 6655                         3push        ebp
7c0A: 6689E5                        mov         ebp,esp
7c0D: EB19                          jmps        000000028 --↓1
7c0F: 67668B4508                   2mov         eax,[ebp][8]
7c14: 67660FB600                    movzx       eax,b,[eax]
7c19: 660FBEC0                      movsx       eax,al
7c1D: 80CC0E                        or          ah,00E
7c20: CD10                          int         010
7c22: 676683450801                  add         d,[ebp][8],1
7c28: 67668B4508                   1mov         eax,[ebp][8]
7c2D: 67660FB600                    movzx       eax,b,[eax]
7c32: 84C0                          test        al,al
7c34: 75D9                          jnz         00000000F --↑2
7c36: 90                           nop
7c37: 665D                          pop         ebp
7c39: C3                            retn ;
7c3A: 6655                          push        ebp
7c3C: 6689E5                        mov         ebp,esp
7c3F: 66684F7C0000                  push        000007C4F ;'  |O'
7c45: E8C0FF                        call        000000008 --↑3
7c48: 6683C404                      add         esp,4
7c4C: 90                            nop
7c4C: 90                            nop
7c4D: C9                            leave
7c4E: C3                            retn ;
7c4F: 48 65 6C 6C 6F-2C 20 57 6F-72 6C 64  Hellow, World

随机地,我注意到指针确实需要移动。对于引导区,需要将代码放在磁盘的第一个扇区,偏移量为0x7C00字节。我在 test.ld 文件中指定它。我试图展示我所拥有的一切。在一堆不同的符号中,潜伏着想要的“你好,世界”。同时,更改代码需要更改偏移量,但我几乎可以肯定它总是大于 0x7C00。仍然需要了解如何正确跟踪此偏移量......

c
  • 1 个回答
  • 10 Views
Martin Hope
Ramil
Asked: 2020-12-17 06:14:39 +0000 UTC

vk中如何获取用户在特定社区留下的评论

  • 10

vk中如何获取特定用户在特定社区帖子下墙上留下的所有评论?

我查看了 vk api 中存在的所有方法,但尚未找到完成此任务的方法。

作为这个问题的初始数据,给出了用户 ID 和社区 ID。

这是我如何尝试实现它的示例:

for i in range(200):
    url = "https://api.vk.com/method/wall.get?owner_id=%s&offset=%s&count=1" % (self.text1.toPlainText(), i)
    response = requests.get(url).text
    parsed_string = json.loads(response)

    url1="https://api.vk.com/method/wall.getComments?owner_id=%s&post_id=%s&count=100" %(self.text1.toPlainText(), parsed_string['response'][1]['items']['id'])

    response1 = requests.get(url1).text
    parsed_string1 = json.loads(response1)

    for j in range(1, len(parsed_string1['response'])):
        if parsed_string1['response'][j]['items']['from_id']==self.text2.toPlainText():
            item1 = QTableWidgetItem(parsed_string1['response'][j]['items']['text'])
            item2 = QTableWidgetItem(str(datetime.datetime.fromtimestamp(parsed_string1['response'][j]['items']['date'])))
            self.tablewidget.setItem(i-1, 0, item1)
            self.tablewidget.setItem(i-1, 1, item2)

但是在这种情况下,对服务器的请求太频繁了,这个选项太沉闷了。请告诉我应该朝哪个方向前进以及您对这个话题有什么想法。

python
  • 1 个回答
  • 10 Views
Martin Hope
firebear
Asked: 2020-12-08 04:18:00 +0000 UTC

如何对数据库中的日期进行碎片整理?

  • 10

你好。我有这个数据库:http ://sqlfiddle.com/#!9/9554b 。第一张表负责显示酒店中存在的房间,第二张表 - 用于显示酒店中的现有预订。我试着想象一下: 图片 sql 代码负责数字的放置/分布顺序。它获取新的入住和退房日期,将它们与主表进行比较,并检查这些日期是否有空房。他将为新装甲分配第一个可用编号。一切都是合乎逻辑的。从这里开始出现这种数字的“混乱”分布。这里其实就是发号的select请求。

SET @start = '2016-12-12'; -- Новая дата заезда
SET @end = '2016-12-20'; -- Новая дата выезда
SELECT a.nomer
FROM allnomer a
LEFT JOIN main m
  ON a.nomer = m.numbernomer
  AND DATEDIFF(m.datestart, @end) * DATEDIFF(m.dateend, @start) <= 0
WHERE a.type = 'lux' AND m.numbernomer IS NULL
LIMIT 1 

但我有一个问题。事实上,12日、13日、14日……20日,没有人住酒店。这些是免费的日子。它们是由于我的脚本分配日期而形成的。但是,如果 12 日到 20 日的预订在 11 日到达,那么脚本将拒绝它(返回 null),因为入住/退房日期重叠。这是意料之中的,但我想解决这个问题。如果您重新分配预订,那么一切都会水到渠成,12 到 20 的号码将会打开。 图片 我没有碰现有的盔甲,我只移动了未来的盔甲。我想知道重新分配/碎片整理的这项工作有多真实,以及如何实现它(也许已经有类似的东西,或者我的案例有这样的 sql 查询)?

php
  • 3 个回答
  • 10 Views
Martin Hope
user216622
Asked: 2020-12-01 03:06:51 +0000 UTC

从文件中读取行时如何删除换行符 (\n)

  • 10

使用 file.readlines() 时,我们得到如下信息:

>>> file.readlines()
['12\n', '10\n', '9\n', '15\n', '10\n', '120']

如何删除\n?

python
  • 3 个回答
  • 10 Views
Martin Hope
Adam Shakhabov
Asked: 2020-11-24 17:09:48 +0000 UTC

在类构造函数中实现 ICollection 接口

  • 10

当我阅读各种教程和我们最喜欢的 StackOverflow 时,我经常看到这样的代码:

namespace MvcApplication2.Models
{
    public class Category
    {
        public int ID { get; set; }

        public string Name { get; set; }
    }

    public class Product
    {
        public ICollection<int> CategoryID { get; set; }

        public Product()
        {
            CategoryID = new List<int>();
        }
    }
}

解释为什么一个属性应该CategoryID声明为一个接口ICollection,如果它在构造函数中用List?

设计师试图通过这种方法避免什么?

我了解是否Product通过其构造函数将某种依赖项引入了该类。但这不存在。

我错过了什么概念点?

c#
  • 2 个回答
  • 10 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5