- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 .ASM 文件,我想在其中调用另一个 .ASM 或 .INC 文件中的过程。
我尝试将以下内容写入我的 main.asm 文件:
INCLUDE file_op.inc
'the emulator is halted.'
; A function to open a file using its name and remember its file_handle
open_file proc
mov ax, 3d00h ; System call to open a file
lea dx, file_name ; name of the file we are opening
int 21h ; system interrupt
mov file_handle, ax ; remember file_handle!!
ret
endp
; A function to read from a file byte by byte using the file_handle we have remembered, and test if we are at the end of the file
read_file proc
mov bx, file_handle
mov cx, 1 ; 1 = number of bytes to read
lea dx, data_from_file ; pointer to reading buffer
mov ah, 3fh ; reading from file via filehandle
int 21h
cmp ax, 0 ; if number of bytes read from file == 0, close file
jz mid_fileclose
ret
endp
; A fucntion to print a character from the file to the screen
data_out proc
mov al, data_from_file ; ASCII code for the last character
mov ah, 09h ; system call for printing strings
lea dx, data_from_file ; address of the string
int 21h ; since al==dx, we print character by character from the file
ret
endp
call open_file
call read_file
call data_out
.model small
.stack 100h
INCLUDE 'file_op.inc'
.data
no_of_lines dw 24 ; number of lines that can be printed within the window, without overwriting old output
printed_lines dw 2 ; number of printed lines we will keep throughout the program, to know when to request user input for moving on to overwriting old output
data_from_file db '.','$' ; a variable where we store characters read from the file
file_handle dw 0 ; file handle using which we read from the file
file_name db "helpDoc.txt", 0 ; name of the file we are reading from
newline db 13,10,'$' ; a variable which we use when we want to print a new line
rrr db '-r' ; a variable against which we compare the user input
size_str = ($ - rrr) ; size of string rrr
argument db 3,?,3 dup(?) ; a variable where we store user input, which defines which mode the program will use
welcome_text db "To print comment lines enter '-r', to print other lines press enter:",13,10,'$' ; a simple welcome text which we display at the start
.code
; A function which prints out a welcome message and promts the user to select the program mode
mode proc
mov ah, 09h ; print out the instruction text
lea dx, welcome_text ; if the user enters '-r', comment lines will be printed
int 21h ; if only enter is pressed, regular lines will be printed
mov ah, 0ah ; system call to get input from the user
lea dx, argument ; storing the input in 'arg' variable
int 21h
mov ah, 09h
lea dx, newline ; print a new line for clear visual effect
int 21h
lea si, [argument + 2] ; load argument (+2 bytes from the address where the string is stored)
lea di, rrr ; load constant rrr = '-r'
mov cx, size_str ; the lenght of the 'arg' variable in bytes
repe cmpsb ; compare the two string until a mismatch occurs, or until cx == 0
jz comments ; if it's not equal, jump to comment, where we print out comment lines from file
ret ; if it's equal, continue to no_comment, where we print out normal lines from file
endp
; Start of the main program
start: mov ax, @data ; load data segment address to ax
mov ds, ax ; move segmet address to ds
mov es, ax ; move segmet address to es
call open_file ; call a procedure to open a file
call mode ; call a procedure to decide which lines we will print from the file
; This is the code section for the no_comment mode, in this mode we print everything except comments ';', '#', '//'.
begin1: call read_file ; read character from file
no_comments: mov al, data_from_file ; move character we have read to al
cmp al, 59 ; compare it against a ';'
je skip_line ; if it's a ';', skip this line from the file and move on to the next one
cmp al, 35 ; compare against a '#'
je skip_line
cmp al, 47
je skip_line ; compare against a '/'
cmp al, 10 ; if it's a newline character, jump to LINE
je new_line1
call data_out ; if none of the above conditions are met, print out the character!
jmp begin1 ; after printing out the character, read from the file again
skip_line: call read_file ; we read from the file, but dont print it on the screen
mov al, data_from_file ; load character we have read into al
cmp al, 10 ; compare it against a newline character
je no_comments ; if there is a match, we are at the end of the line and we start again from no_comment
jmp skip_line ; if we are not at the end of the line we repeat until we are
new_line1: mov ah, 09h ; system call to print a string
lea dx, newline ; print a new line
int 21h
inc printed_lines
mov ax, printed_lines
mov dx, no_of_lines
cmp ax, dx
je wait_for_input1
jmp begin1 ; after we have printed a new line, we read from the file again
mid_fileclose: jmp fileclose ; jump in the read_file procedure was too long so we have a mid jump here
wait_for_input1:mov ah, 07h ; DOS.InputCharacterWithoutEcho
int 21h
mov printed_lines, 0
mov ax, 3
int 10h
jmp begin1
; This is the code section for the COMMENT mode, here we print only comments
begin2: call read_file ; read a character from the file
comments: mov al, data_from_file ; move the character into the al, so we can compare it
cmp al, 59 ; compare against ';'
je new_line2 ; if equal, jump to new_line to print a new line and print until end of line
cmp al, 47 ; compare against '/'
je new_line2
cmp al, 35 ; compare against '#'
je new_line2 ; if none of the conditions above are met, it is not a comment and we dont print anything
skip: call read_file ; read a character from the file, but dont print it
mov al, data_from_file ; move it to al, so we can compare it
cmp al, 10 ; if it is a newline character, we are at the end of a line and we read from the file again
je begin2
cmp al, 59 ; compare against ';'
je comments ; if it's equal, jump to comment a start printing out this line of the file
cmp al, 47 ; compare against '/'
je comments
cmp al, 35 ; compare against '#'
je comments
jmp skip ; if none of the above conditions are met, cycle read through the file
print: call data_out ; print the character on the screen
call read_file ; read another one from the file
mov al, data_from_file ; move it to al, so we can compare it
cmp al, 10 ; if it is a newline character, we are at the end of a line and we read from the file again
je begin2
jmp print ; cycle through the characters in the line of the file until a newline character is found
new_line2: mov ah, 09h ; system call to print a string
lea dx, newline ; print a new line
int 21h
inc printed_lines
mov ax, printed_lines
mov dx, no_of_lines
cmp ax, dx
je wait_for_input2
jmp print ; after we have printed a new line, we start printing out the contents of the comment line from the file
wait_for_input2:mov ah, 07h ; DOS.InputCharacterWithoutEcho
int 21h
mov printed_lines, 0
mov ax, 3
int 10h
jmp begin2
; After we have read everything from the file, we close it and exit the program
fileclose: mov bx, file_handle ; load file handle as an argument for system call
mov ah, 3eh ; close the file using the system call
int 21h
exit: mov ax, 4c00h ; system call to exit the program
int 21h
end start
最佳答案
包含指令 INCLUDE file_op.inc
与将文件的文本直接复制并粘贴到程序集文件中的操作相同,其中 INCLUDE
指令出现。您在 .code
之前包含了一个带有代码的文件已遇到指令。您需要将它包含在 .code
之后.将包含移动到文件中的这一点:
.code
INCLUDE file_op.inc ; <--- Inserted after .code
mode proc
关于assembly - 从另一个文件调用过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55145277/
我被告知“汇编”是您在文件中编写的内容,让您的“汇编程序”将其转换为二进制代码。 但我看到这两个术语在各种作品中混合搭配。我什至听说你编写了“汇编器”,然后“汇编器”使其可执行。 正确的用词是什么?
我在正确终止用 Assembly 编写的 16 位 DOS 程序时遇到问题。这是部分代码: .386P .model flat stack_s segment stack 'stack'
我需要多少档才能正确执行以下指令。我对我所做的事情有些困惑,所以我在这里看到专家的答案。 lw $1,0($2); beq $1,$2,Label; 请注意,检查是否会发生分支将在解码阶段完成。但是在
我正在尝试在汇编中进行简单的乘法运算,但是由于某些原因,当标记了MUL函数时,我看不到寄存器会发生变化。 mov bx, 5 mov cx, 10 mul cx 最佳答案 这些称为指令,它们指定
我正在尝试在 Assembly 中实现递归斐波那契程序。但是,我的程序崩溃了,出现了未处理的异常,我似乎无法找出问题所在。我不怀疑这涉及我对堆栈的不当使用,但我似乎无法指出哪里...... .386
我编写了以下代码: .386 .model small .stack 100h .data text db "Paper",0 .code start : lea dx ,
我有一个用汇编语言编写的裸机 ARM 的启动代码,我正在尝试了解它是如何工作的。该二进制文件被写入一些外部闪存中,并在启动时将其自身的一部分复制到 RAM 中。尽管我读过这篇文章wikipedia e
我在数据部分定义了一个二维数组和两个一维数组(一个用于列总和,一个用于行总和),并且我编写了一个函数,将二维数组求和到一维数组中。我使用 eax 和 ebx 作为二维数组的索引,但是当 eax 或 e
我正在开始组装,我正在使用 nasm 来组装代码,我正在尝试处理驻留在内存中的字符串并更改它,我想检查一个字节是否在某个范围内(ascii),这样我就可以决定如何处理它,我似乎不知道如何检查一个值是否
虽然您通常不希望将一个整体程序集用于小型项目以外的任何事情,但可能会将事物分离得太多。 组装分离过多的迹象/气味是什么? 最佳答案 第一个(明显的)是:在一个有很多项目的解决方案中,其中只有少数(比如
我正在尝试编写斐波那契的汇编代码版本,它给出第 n 个斐波那契数并返回它。 出于某种原因,它在存储斐波那契数的返回值和添加它们时遇到问题。 我希望它打印第 n 个斐波那契数。 我对我的代码做了一些修改
我有一个最小的、可重现的示例有两个问题,该示例具有三个针对 .NET Core 3.1 的项目。但我也想以 .NET Standard 2.0 为目标。 该示例适用于需要在运行时加载程序集并使用提供的
: 运算符在汇编中做什么?代码如下:DS:DX我还没有找到该运算符(operator)的任何文档。(我正在使用 NASM) 最佳答案 那实际上只是一个寄存器分隔符,而不是运算符。这意味着使用 DX 寄
我在哪里可以找到为 gmp-5.0.0 编写的程序的汇编代码我正在使用 UBUNTU 和 G++ 编译器..编译代码的命令是“g++ test.cc -o outp -lgmp” 实际上我想知道在 1
我是组装新手,我有一个关于如何表示负数的问题 我有三个 DWORDS 变量,比如说: result DWORD 0 i DWORD 3 j DWORD 5 我想计算这个公式:result = i -
我想编写我的第一个汇编程序。我在论文上做了一些程序,但这是我第一次使用编译器。我正在使用 ideone .我的程序很简单, 翻译 A = 5 - A到 assembly NEG A ADD A, 5
程序集,masm 嘿,我写了宏来打印存储在 dane1 段中的 1 字节值。 我将值除以 16,然后将提醒推送到堆栈,直到值==0。然后我弹出提醒将它们转换为 ASCII 码,并打印它们。 有人可以看
我正在研究 nasm 的一个大学项目。唯一的问题是我无法生成 162 和 278 之间的偶数随机数。我尝试了很多算法,但似乎无法限制范围内的数字。 是否有一个小技巧或调整来获得所需的范围内的数字?目的
终于在无数次错误的漫长 session 之后,希望这是最后一个。 没有编译或运行时错误,只是一个逻辑错误。 编辑:(固定伪代码) 我的伪代码: first = 1; second = 1; thir
我知道在程序集r0中调用函数时,包含第一个参数,直到r3是第四个。我知道,当它超过四个时,将使用堆栈指针,但是我不太确定具体细节。 r0-r3仍然保持前四个,其余的进入堆栈吗?我正在看下面的程序集,试
我是一名优秀的程序员,十分优秀!