【发布时间】:2018-07-22 08:00:27
【问题描述】:
此代码有错误。 print_string 在指向字符串后不会打印到屏幕上,它只会在代码mov bx,8000h 中的行被删除并且它之后的两行之后打印,但是我不能写很多字节来撞击整个事情在调用后崩溃分配并增加基指针 20 次。我应该怎么做,如何写字符串并使其在写入 20 个字节后不会崩溃
[bits 16]
[org 0x7c00]
SEAM_STD_BUFFER equ 0
SEAM_STD_LIMIT equ 255
xor ax,ax
mov bx,ax
mov bx,cx
mov dx,0
mov ds,bx
mov es,bx
mov bp,0
mov sp,bp
mov ss,bp
mov bx,8000h
mov sp,bx
mov ss,bx
mov bp,0
jmp _start
_start:
call clear
.repeat:
mov bp, OS_USERNAME_DESCRIPT
call print_string
call Set_BasePointer_std
call read_string_show
jmp .repeat
Set_BasePointer_std:
mov bp,SEAM_STD_BUFFER
ret
read_char_show:;() returns al
call read_char
cmp al,8
je .back
call print
ret
.back:
cmp bp,SEAM_STD_BUFFER
je .done
call print
.done:
mov al,0
ret
read_string: ; (ptr bp place to allocate string)
call read_char
cmp al,13
je .done
call alloc
inc bp
cmp bp,SEAM_STD_LIMIT
jge .resetbp
jmp read_string
.done:
mov al,0
call alloc
ret
.resetbp:
call Set_BasePointer_std
jmp read_string
read_string_show: ; (ptr bp place to allocate string)
call read_char_show
cmp al,0
je read_string_show
cmp al,13
je .done
cmp al,8;;NOT GOOD ENOUGH
je .skip;;NOT GOOD ENOUGH
call alloc
inc bp
.skip:;;NOT GOOD ENOUGH
cmp bp,SEAM_STD_LIMIT
jge .resetbp
jmp read_string_show
.resetbp:
call Set_BasePointer_std
jmp read_string
.done:
mov al,0
call alloc
call next_line
ret
read_char: ;() returns al
mov ax,0x00
int 0x16
ret
clear:; ()
mov ah,0
mov al,3
int 0x10
ret
free:;(bp ptr at place start to free, ax at end )
mov [bp],byte 0
cmp bp,ax
je .done
inc bp
jmp free
.done:
ret
dalloc:; (ptr bp)
mov al,[bp]
ret
alloc: ;(bp place to allocate,al byte value)
mov [bp], al
ret
clear_line:
mov dh,0
call clear
ret
next_line:
mov ah,2
mov dl,0
inc dh
cmp dh ,25
jge clear_line
int 10h
ret
previous_line:
dec dh
mov ah,2
mov dl,0
int 10h
ret
next_char:; finish
string_compare:;finish
print: ; (al Character to print, bl color)
mov ah,0x0E
int 10h
ret
print_string: ;(ptr bp Place of string start)
call dalloc
cmp al,0
je .done
call print
inc bp
jmp print_string
.done:
ret
OS_WELCOME db 'What is giong on',0
OS_USERNAME_DESCRIPT db 'Username:'
times (510 - ($-$$)) db 0x00
dw 0xAA55
【问题讨论】:
-
您是 16 位汇编代码开发的新手吗?我问是因为您的函数操作方式、不寻常的 dalloc 例程以及您在代码的顶部
-
是的,我是新手,请告诉我如何设置段寄存器
-
我会开始很简单。暂时忘记输入。您是否尝试过创建仅在屏幕上显示字符串的工作代码?
-
是的,一切打印都运行良好,除非我添加 mov bp,8000h mov ss,bp 它搞砸了
-
您已标记此 emu8086。它看起来像鼻塞。你在用emu8086吗?
标签: assembly nasm x86-16 bootloader bios