我想要分类的emu8086程序

时间:2015-04-15 12:00:31

标签: assembly

我想要一个“EMU 8086”程序,它可以在0-300之间对字符串中的数字进行分类 并打印数字0-100在侧面,100-200在另一个,200-300 ??

我尽我所能,我的程序不打印价值..!

org 100h

s1 dw 50,60,70,80,90,100,120,130,140,160,170,190,190,220,250,270,300

MOV SI,0
MOV CX,16

s2:
MOV AX,s1[SI]

s3:
INC SI
CMP AX,100
JBE s4
JA s5

s4:
PRINTf AX
JMP s3

s5:
CMP AX,200
JB s6
JA s7

s6:
PRINTf AX
JMP s3

s7:
PRINTf AX
JMP s3


END

1 个答案:

答案 0 :(得分:0)

这是您的EMU8086 Intel语法程序。您只需复制粘贴并运行即可。这是它的工作原理:DI指向数字,取决于数字是否<100,100..200,> 200,有必要确定数字是在左,中,右列,然后我们做gotoxy(发送光标到屏幕坐标),现在我们必须将数字转换为字符串(因为二进制在屏幕上看起来很奇怪),最后,我们显示数字。如果下一个数字不为零(零完成该过程),则重复下一个数字。

.stack 100h
.data

numbers dw 130,50,260,570,180,190,100,20,66,140,860,470,190,20,220,250,170,30,300,0

col1 db 0  ;ROW NUMBER FOR THIS COLUMN.
col2 db 0  ;ROW NUMBER FOR THIS COLUMN.
col3 db 0  ;ROW NUMBER FOR THIS COLUMN.

str  db 6 dup('$') ;STRING TO STORE NUMBER CONVERTED INTO STRING.

.code          
;INITIALIZE DATA SEGMENT.
  mov  ax, @data
  mov  ds, ax

  mov  di, offset numbers  ;DI POINTS TO THE NUMBERS.
while:
;FIND OUT IF NUMBER BELONGS TO LEFT, MIDDLE OR RIGHT COLUMN.
  mov  ax, [ di ]  ;GET CURRENT NUMBER.
  cmp  ax, 100
  jb   left_column  ;IF NUMBER < 100 LEFT_COLUMN.
  cmp  ax, 200
  ja   right_column  ;IF NUMBER > 200 RIGHT_COLUMN.
;IF NO JUMP, THEN NUMBER >= 100 AND NUMBER <= 200.
  mov  dl, 30    ;SCREEN COLUMN.
  mov  dh, col2  ;SCREEN ROW.
  call gotoxy    ;SET CURSOR POSITION.
  inc  col2      ;INCRESE ROW FOR NEXT NUMBER ON THIS COLUMN.
  jmp  continue

left_column:             
  mov  dl, 0     ;SCREEN COLUMN.
  mov  dh, col1  ;SCREEN ROW.
  call gotoxy    ;SET CURSOR POSITION.
  inc  col1      ;INCRESE ROW FOR NEXT NUMBER ON THIS COLUMN.
  jmp  continue

right_column:  
  mov  dl, 60    ;SCREEN COLUMN.
  mov  dh, col3  ;SCREEN ROW.
  call gotoxy    ;SET CURSOR POSITION.
  inc  col3      ;INCRESE ROW FOR NEXT NUMBER ON THIS COLUMN.
  jmp  continue

continue:           
;CONVERT CURRENT NUMBER TO STRING.
  call dollars  ;FILL "STR" WITH '$'. NECESSARY TO DISPLAY IT.
  mov  ax, [ di ]  ;GET CURRENT NUMBER.
  call number2string  ;CONVERT AX TO STRING. RESULT IN "STR".  
;DISPLAY NUMBER CONVERTED.  
  mov  ah, 9
  mov  dx, offset str
  int  21h        
;NEXT NUMBER TO PROCESS.  
  add  di, 2  ;2 BYTES FORWARD BECAUSE NUMBERS ARE "DW".
;CHECK IF PROCESS IS OVER.  
  mov  ax, [ di ]
  cmp  ax, 0
  jne  while  ;IF AX!=0 JMP WHILE.

;FINISH PROGRAM.
  mov  ax, 4c00h
  int  21h           

;------------------------------------------
;MOVES CURSOR TO SCREEN COORDINATES DL,DH (COLUMN,ROW).

proc gotoxy
  mov  ah, 2
  mov  bh, 0
  int  10h
  ret
endp  

;------------------------------------------
;NUMBER TO CONVERT MUST ENTER IN AX.
;ALGORITHM : EXTRACT DIGITS ONE BY ONE, STORE
;THEM IN STACK, THEN EXTRACT THEM IN REVERSE
;ORDER TO CONSTRUCT STRING.

proc number2string
  mov  bx, 10 ;DIGITS ARE EXTRACTED DIVIDING BY 10.
  mov  cx, 0 ;COUNTER FOR EXTRACTED DIGITS.
cycle1:       
  mov  dx, 0 ;NECESSARY TO DIVIDE BY BX.
  div  bx ;DX:AX / 10 = AX:QUOTIENT DX:REMAINDER.
  push dx ;PRESERVE DIGIT EXTRACTED FOR LATER.
  inc  cx ;INCREASE COUNTER FOR EVERY DIGIT EXTRACTED.
  cmp  ax, 0  ;IF NUMBER IS
  jne  cycle1 ;NOT ZERO, LOOP. 
;NOW RETRIEVE PUSHED DIGITS.
  mov  si, offset str
cycle2:  
  pop  dx        
  add  dl, 48 ;CONVERT DIGIT TO CHARACTER.
  mov  [ si ], dl
  inc  si
  loop cycle2  

  ret
endp  

;------------------------------------------
;FILLS VARIABLE STR WITH '$'.
;USED BEFORE CONVERT NUMBERS TO STRING, BECAUSE
;THESE STRINGS WILL BE DISPLAYED.

proc dollars                 
  mov  si, offset str
  mov  cx, 6
six_dollars:      
  mov  al, '$'
  mov  [ si ], al
  inc  si
  loop six_dollars
  ret
endp

如果这有助于你,请告诉我。