-int HaveSegmentChange (unsigned Addr)
-/* Return true if the segment change attributes are set for the given address */
-{
-    return (GetAttr (Addr) & (atSegmentStart | atSegmentEnd)) != 0x0000;
-}
-
-
-
 unsigned GetGranularity (attr_t Style)
 /* Get the granularity for the given style */
 {
 
 int IsSegmentStart (unsigned Addr);
 /* Return true if a segment starts at the given address */
 
-int HaveSegmentChange (unsigned Addr);
-/* Return true if the segment change attributes are set for the given address */
-
 unsigned GetGranularity (attr_t Style);
 /* Get the granularity for the given style */
 
 
 static void OneOpcode (unsigned RemainingBytes)
 /* Disassemble one opcode */
 {
+    unsigned I;
+
     /* Get the opcode from the current address */
     unsigned char OPC = GetCodeByte (PC);
 
     **   - ...if we have enough bytes remaining for the code at this address.
     **   - ...if the current instruction is valid for the given CPU.
     **   - ...if there is no label somewhere between the instruction bytes.
-    ** If any of those conditions is false, switch to data mode.
+    **   - ...if there is no segment change between the instruction bytes.
+    ** If any one of those conditions is false, switch to data mode.
     */
     if (Style == atDefault) {
         if (D->Size > RemainingBytes) {
             Style = atIllegal;
             MarkAddr (PC, Style);
         } else {
-            unsigned I;
-            for (I = 1; I < D->Size; ++I) {
-                if (HaveLabel (PC+I)) {
+            for (I = PC + D->Size; --I > PC; ) {
+                if (HaveLabel (I) || IsSegmentStart (I)) {
                     Style = atIllegal;
                     MarkAddr (PC, Style);
                     break;
                 }
             }
-            for (I = 1; I < D->Size - 1u; ++I) {
-                if (HaveSegmentChange (PC+I)) {
+            for (I = 0; I < D->Size - 1u; ++I) {
+                if (IsSegmentEnd (PC + I)) {
                     Style = atIllegal;
                     MarkAddr (PC, Style);
                     break;
             */
             if (D->Size <= RemainingBytes) {
                 /* Output labels within the next insn */
-                unsigned I;
                 for (I = 1; I < D->Size; ++I) {
                     ForwardLabel (I);
                 }
             DataByteLine (1);
             ++PC;
             break;
-
     }
 
-    if (IsSegmentEnd (PC - 1)) {
-        EndSegment ();
+    /* Change back to the default CODE segment if
+    ** a named segment stops at the current address.
+    */
+    for (I = D->Size; I >= 1; --I) {
+        if (IsSegmentEnd (PC - I)) {
+            EndSegment ();
+            break;
+        }
     }
 }