【问题标题】:How do we compare two 2-byte binary numbers in 8085?我们如何比较 8085 中的两个 2 字节二进制数?
【发布时间】:2013-09-29 17:27:27
【问题描述】:

我必须为以下内容编写一个微处理器 8085 汇编语言代码:-

从 2400H/0C20H 开始,6 个国家/地区的人口普查存储在 18 个位置。第一个字节是代码编号(可以从 00H 到 05H),接下来的 2 个字节是二进制的国家人口(每个国家占 3 个位置)。我必须找到人口最多的国家,并将其国家代码存储在位置 2500H/0C90H。

我在整个互联网上进行了搜索,但找不到我们如何比较 8085 中的两个 2 字节二进制数?如果您能提供帮助将不胜感激。

【问题讨论】:

  • 那么,你知道如何比较两个 1 字节的数字吗?
  • 一次完成一个字节。 :) 显示一些代码以及卡住的地方。

标签: assembly 8085


【解决方案1】:

在 8 位 CPU 上,您比较第一个(= 最高)字节。如果相等,则比较第二个(= 较低)字节。比较 32 位或 64 位数字时,您继续使用第三个字节,依此类推。当字节不相等时停止比较。

在 Z80 上,您还可以使用指令“SBC HL,DE”进行 16 位比较。但是这个指令在 8085 上不存在。

8 位处理器的示例:

 LOAD register1, [high byte of A]
 LOAD register2, [high byte of B]
 COMPARE register1, register2
 JUMP_IF_EQUAL was_equal
   // -- This is used for 32- and 64-bit numbers only --
 LOAD register1, [second byte of A]
 LOAD register2, [second byte of B]
 COMPARE register1, register2
 JUMP_IF_EQUAL was_equal
   ...
   // -- --
 LOAD register1, [low byte of A]
 LOAD register2, [low byte of B]
 COMPARE register1, register2
was_equal:
  // Here the status flags are set as if a 16-bit UNSIGNED
  // COMPARE had been done.

用处理器的正确指令替换指令“LOAD”等!

有符号数比较更难!

【讨论】:

  • 非常感谢您的帮助!!我想我现在很快就会想出一个解决方案并在这里发布。
【解决方案2】:

终于在朋友的帮助下解决了。这是:-

KickOff 2050H                  ;where to start the program
Org 2050H                      ;where to start the code

lxi sp,23ffH                   ;initializing stack pointer to 23ffH
lxi hl,0000H                   ;resulting population to 00 initially for comparison
shld 2501H                     ;store this poulation (00) to 2501h
lxi hl,2400h                   ;now load the address of start loc of data

mvi c,06h                      ;counter for 6 countries

loop:
     mov d,m                   ;store the index of current country in d register
     inx hl                    ;increase hl pair
     mov b,m                   ;store the first byte of current population in b
     inx hl   
     mov e,m                   ;store the second byte of current population in e
     push hl                   ;push hl pair onto stack for later use
     lxi hl,2501h               
     mov a,b

     cmp m                     ;compare first byte (a-m) will set c=1 if m>a
     jc next                   ;if carry do nothing
     jz next1                  ;if z=1, they are equal so we compare next two bytes
     mov m,a                   ;if current greater than previous value then change values of 2501 and 2502 and also index
     inx hl                     
     mov m,e
     mov a,d
     sta 2500h                 ;ab kitna samjaye, kr lo khud se
     jmp next

next1:
     inx hl
     mov a,e
     cmp m
     jc next
     mov m,e
     dcx hl
     mov m,b
     mov a,d
     sta 2500h

next:
     pop hl
     inx hl
     dcr c
     jnz loop
     hlt

谢谢大家的回答!! :)

【讨论】:

    【解决方案3】:
    mvi a, 1st no.  
    mvi b, 2nd no.  
    cmp b  
    jc go   
    mov a,b  
    go: sta 0020h  
    hlt
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 2016-06-29
      • 2011-06-14
      • 2011-09-06
      • 1970-01-01
      • 2012-06-29
      相关资源
      最近更新 更多