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

8085汇编代码修改求助:从给定数字列表中分离奇数并存储至新列表

Fixing 8085 Assembly Code to Separate Odd Numbers from a List

Let's break down why your current code captures even numbers instead of odd ones, then fix it step by step.

What's Wrong with the Original Code?

Your jump condition is reversed, which flips the logic:

  • ANI 01H checks the least significant bit (LSB) of the number. If the number is odd, the LSB is 1, so ANI 01H results in 01H and the Zero Flag (Z) is cleared.
  • JNZ SKIP means "Jump to SKIP if the Zero Flag is NOT set" — so when you have an odd number, you jump over the storage code and ignore it.
  • When the number is even, the LSB is 0, ANI 01H gives 00H, the Zero Flag is set, JNZ doesn't trigger, so you store the even number instead.

Modified Code to Capture Odd Numbers

We just need to flip the jump condition to skip storage only when the number is even:

LXI H, 2200H   ; Load source list starting address into HL pair
LXI D, 2300H   ; Load destination list starting address into DE pair
MVI C, 32H     ; Set counter to 50 (32H in hex) — adjust if your list size differs
BACK: MOV A, M ; Move current number from source to accumulator A
ANI 01H        ; Check LSB: result is 1 if odd, 0 if even
JZ SKIP        ; Jump to SKIP if Zero Flag is set (i.e., number is even)
MOV A, M       ; Reload the original odd number into A (ANI modified the value)
STAX D         ; Store the odd number at the destination address
INX D          ; Increment destination pointer to next empty location
SKIP: INX H    ; Increment source pointer to the next number in the list
DCR C          ; Decrement the counter
JNZ BACK       ; Repeat until all numbers are processed
HLT            ; Halt the program

Key Change Explained

The only critical modification is replacing JNZ SKIP with JZ SKIP:

  • Now, when the number is even (Zero Flag set), we jump to SKIP and skip storing it.
  • When the number is odd (Zero Flag cleared), we proceed to store it in the destination list.

Quick Note on Reloading the Number

We have to reload the original number into A with MOV A, M after ANI 01H because the ANI instruction modifies the accumulator's value (turning it into 00H or 01H). Without this step, we'd store 01H instead of the actual odd number — so don't skip this line!

This modified code will correctly iterate through your source list at 2200H, pick out all odd numbers, and store them sequentially starting at 2300H.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 05:47:34