AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-5328289

M.E.'s questions

Martin Hope
M.E.
Asked: 2025-03-09 21:07:51 +0800 CST

真实模式下的 Hello World

  • 6

我正在尝试在实模式下编写一个将在 QEMU 中运行的示例“Hello World”。主机是运行 FreeBSD 14 的 64 位英特尔。

我尝试了以下方法:

这是boot.asm文件:

format binary
org 0x7C00      ; Bootloader loaded at 0x7C00

start:
    ; Set up segment registers
    mov ax, cs
    mov ds, ax
    mov es, ax

    ; Set up stack
    mov ax, 0x0000
    mov ss, ax
    mov sp, 0x7C00

    ; Print message using BIOS interrupt
    mov si, msg
print_loop:
    lodsb               ; Load next character
    test al, al
    jz halt             ; Jump if null terminator
    mov ah, 0x0E        ; BIOS teletype function
    int 0x10            ; Call BIOS
    jmp print_loop

halt:
    cli                 ; Disable interrupts
    hlt                 ; Halt processor

msg db "Hello, World!", 0

times 510 - ($-$$) db 0 ; Pad to 510 bytes
dw 0xAA55               ; Boot signature

这是 makefile:

# Makefile for FreeBSD bootloader example

ASM = fasm
QEMU = qemu-system-i386
TARGET = boot.bin
SOURCE = boot.asm

all: $(TARGET)

$(TARGET): $(SOURCE)
        $(ASM) $(SOURCE) $(TARGET)

run: $(TARGET)
        $(QEMU) -fda boot.bin -serial stdio -display none

clean:
        rm -f $(TARGET)

这是我组装文件并通过 qemu 运行后得到的结果:

$ make
fasm boot.asm boot.bin
flat assembler  version 1.73.32  (16384 kilobytes memory)
2 passes, 512 bytes.

$ make run
qemu-system-i386 -fda boot.bin -serial stdio -display none
WARNING: Image format was not specified for 'boot.bin' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.

一些问题:

  1. 我希望 -serial stdio 捕获示例引导加载程序显示的消息的输出,但没有显示任何消息。
  2. 如何指定 qemu 的文件格式以便不再显示警告。
assembly
  • 1 个回答
  • 34 Views
Martin Hope
M.E.
Asked: 2024-12-02 22:40:46 +0800 CST

如何使用 awk 用环境变量替换模式?

  • 8

我正在尝试编写一个简单的脚本,它将通过标准输入接收文本并按原样输出所有内容,但它将替换遵循以下模式的出现:

{{env MYVAR}} 
{{env PATH}} 
{{env DISPLAY}} 

与环境变量 MYVAR、PATH、DISPLAY 等的内容相关。

我的目标是不向该脚本传递任何参数,因此它将自动检测模式并用环境变量{{env VARNAME}}的值替换。$VARNAME

该脚本通过标准输入获取输入并通过标准输出提供输出。

通过标准输入的示例输入文本:

This is a basic templating system that can replace environment variables in regular text files.
For example the DISPLAY in this system is {{env DISPLAY}} and the path is {{env PATH}}.

通过标准输出的预期输出:

This is a basic templating system that can replace environment variables in regular text files.
For example the DISPLAY in this system is :0.0 and the path is /bin;/usr/bin;/usr/local/bin.

我已尝试过:

到目前为止,我只设法通过命令行传递一个变量来完成此操作。

#!/bin/sh

# Check if the first argument is set
if [ -z "$1" ]; then
    echo "No variable name provided." >&2
    exit 1
fi

VARIABLE_NAME="$1"

# Use awk to replace '{{env VARIABLE_NAME}}' with the value of the environment variable
awk -v var_name="$VARIABLE_NAME" '
function escape(s) {
    esc = "";
    for (i = 1; i <= length(s); i++) {
        c = substr(s, i, 1);
        if (c ~ /[.[\]$()*+?^{|\\{}]/) {
            esc = esc "\\" c;
        } else {
            esc = esc c;
        }
    }
    return esc;
}
BEGIN {
    search = "{{env " var_name "}}";
    search_esc = escape(search);
    replacement = ENVIRON[var_name];
}
{
    gsub(search_esc, replacement);
    print;
}'

因此,上述方法有效,但需要你做./parsing_script MYVAR

我想避免将环境变量指定为命令行参数。

架构/操作系统

我正在使用 FreeBSD 的 awk 及其 POSIX shell /bin/sh

笔记

如果 awk 不是合适的工具,我愿意听取解决方案(请不要使用 Python 或 Perl)。

bash
  • 5 个回答
  • 96 Views
Martin Hope
M.E.
Asked: 2024-08-27 00:27:51 +0800 CST

vim 中可以有模态弹出菜单吗?

  • 5

我编写了一个函数,给定一个目录和标题,显示一个弹出窗口,其中包含该文件夹中包含的所有文件:

function! ListFiles(dir, title)
  let l:dir = a:dir
  let l:title = a:title
  let l:files = glob(l:dir . '/*', 0, 1)
  let l:file_list = []
  for l:file in l:files
    call add(l:file_list, fnamemodify(l:file, ':t'))
  endfor

  " Define custom highlight groups
  highlight PopupMenu guifg=#ffffff guibg=#333333 ctermfg=white ctermbg=darkred
  highlight PopupMenuSelected guifg=#000000 guibg=#ffff00 ctermfg=black ctermbg=yellow

  " Create a popup menu with the file list
  let l:selected_file = popup_menu(l:file_list, {
        \ 'title': ' ' . l:title . ' ',
        \ 'callback': 's:HandleFileSelection',
        \ 'line': &lines / 2,
        \ 'col': &columns / 2,
        \ 'highlight': 'PopupMenu',
        \ 'border': [],
        \ 'close': 'click',
        \ 'padding': [1, 2, 1, 2],
        \ 'mapping': 0,
        \ 'filter': 'popup_filter_menu',
        \ 'wrap': 0
        \ })

  " Define a function to handle the selection
  function! s:HandleFileSelection(id, result)
    let l:file_name = ""
    if a:result != -1
      let l:file_name = getbufline(winbufnr(a:id), a:result)[0]
    endif
    echom "FOO.".l:selected_file
    return l:file_name
  endfunction

  " Return file
  echom "BAR.".l:selected_file
  return l:selected_file

endfunction

但是,当我运行它时,我可以看到,一旦您在某个项目上按下回车键,在出现消息(带有选定的文件)BAR...之前会显示该消息(带有数字) 。FOO...

因此看起来代码首先执行ListFiles函数的返回,然后执行处理程序的返回。

为什么会发生这种情况?哪种方法可以仅获得所选项目的单个返回值?

vim
  • 1 个回答
  • 28 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve