You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

8086汇编程序始终输出相同字符串问题求助

Alright, let's figure out why your emu8086/FASM program is always spitting out "overflow flag set" no matter what's going on with the overflow flag, and fix this issue step by step.

The Core Problem

From your description, it sounds like you're making a critical mistake in how you're handling the overflow flag check and string output: you're likely trying to jump directly to the string's memory address (0 for o_set, 13h for o_notset) instead of jumping to code that uses DOS interrupts to print those strings. When you jump to a string address, the CPU treats the ASCII characters as machine instructions—this is why your program behaves unpredictably, regardless of what value you load into DX.

How to Fix It

First, remember that in 8086 DOS programs, you use the INT 21h interrupt (with AH=09h) to print null-terminated strings (ending with $). To branch based on the overflow flag, use the dedicated conditional jump instructions: JO (Jump if Overflow) and JNO (Jump if No Overflow).

Here's a corrected example of your program structure in FASM syntax:

org 100h

; First test: addition without overflow
mov al, 10
add al, 20
; Check overflow flag and branch
jno print_not_overflowed  ; Jump if OF is NOT set
jo print_overflowed       ; Jump if IS set

print_not_overflowed:
mov dx, offset o_notset   ; Load address of the "not set" string
mov ah, 09h               ; DOS function for string print
int 21h                   ; Trigger interrupt to print
jmp program_end           ; Skip to exit

print_overflowed:
mov dx, offset o_set      ; Load address of the "set" string
mov ah, 09h
int 21h

program_end:
mov ah, 4Ch               ; DOS function to exit program
int 21h

; String definitions (must end with $ for INT 21h AH=09h)
o_notset db 'Overflow flag not set$'
o_set db 'overflow flag set$'

Key Corrections Explained

  • Conditional Jumps: JNO and JO directly check the overflow flag (OF) in the flags register—this is the proper way to branch based on overflow status, not manually loading addresses into DX and jumping.
  • String Output Logic: We load the string's offset into DX, then call INT 21h with AH=09h to print the string up to the $ terminator. This is the standard DOS method for printing strings, not jumping to the string itself.
  • Program Flow: After printing, we jump to the exit code to avoid accidentally executing the other print block.

Debugging Tip

In emu8086, use the step-by-step execution (F8) to track:

  1. The value of the overflow flag (OF) in the flags register after your addition operation.
  2. Whether the conditional jump (JO/JNO) branches to the correct print block.
  3. That your strings correctly end with $—missing this will cause the interrupt to print garbage until it hits a $ in memory.

内容的提问来源于stack exchange,提问作者the_endian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:20:04