"Assembly language" Wang Shuang experimental version 10

1. Display String

the ASSUME CS: code 
Data segment 
   DB ' available for purchase to MASM! ' , 0 
Data ends 

code segment 
Start:  MOV DH, . 8           ; the number of rows 
       MOV DL, . 3           ; the number of columns 
       MOV Cl, 2           ; green 
       MOV AX, Data
        MOV DS, AX
        MOV Si, 0           ; data 
       Call show_str 

       MOV AX, 4c00h
        int 21H 

; at the specified location with the specified color, a display string ends with 0 
;Parameters: (dh) = row number (in the range 0 ~ 24), (dl) = column number (in the range 79 ~ 0), 
; (Cl) = color, ds: si points to the first address of the string 
; Back : no 
show_str: 
        MOV AX, 0b800h
         MOV ES, AX
         MOV DI, 0         ; memory 0 0 row 0 

        MOV Al, 160.       ; calculation line start 
        MUL DH
         the Add DI, AX 

        MOV Al, 2         ; computed column start 
        MUL DL
         the Add DI, AX 

        MOV BL, Cl   
 S: 
        MOV Cl, [Si]
         MOV CH, 0 
        jcxz OK
         MOV es:[di],cl
        mov es:[di+1],bl    ;color
        inc si
        add di,2
        loop s
ok:
        ret
code ends
end start

2. solve the problem of the division overflow

This question is very simple meaning, the result is talking about the dividend divided by the divisor to get high 16 as a result of the high 16, and the result is divided by the divisor to get the low dividend of 16 as a result of the lower 16 bits.

the ASSUME  CS: code 
code segment 
Start:  MOV  AX, 4240H              ; lower 16 
       MOV  DX, 000FH              ; high 16-bit     
       MOV  CX, 0AH                 ; Divisor -> remainder 
       Call  divdw 

       MOV  AX, 4c00h
        int  21H 

;  Function: no overflow division operation, the dividend is a dword type divisor word type, the result is dword type 
;  parameters: (ax) = low dword type data 16 
;        (DX) = high 16-bit dword type data 
;        (CX) = divisor 
;  returns: (dx) = 16-bit result of high, low (ax) = 16-bit result 
;        (CX) = remainder 
divdw:  MOV  BX, AX      ;  Save low 
MOV  ax, DX       ; high operation MOV  DX, 0H       ;  for H / N calculation div  CX          ;  dividend since the divisor is 16 bits, the use of div, is set to 32 ; divisor of 16, commercially presence ax in the presence of the remainder dx in MOV  Si, AX
            ;  to save int (H / N), because the rem (H / N) * 65536 is equivalent to the upper 16 bits, dx, and therefore the remainder obtained do high direct dx MOV  ax, BX       ;  [REM (H / N) * 65536 + L] div  CX          ;  [REM (H / N) * 65536 + L] / N, the result is the ax saved as 16-bit low-order ; divisor 16, business exists ax, there is remainder in dx mov  CX, dx       ;  the remainder is written CX mov  dx, Si       ;  the high write dx
       
       
       
       
       

       
       
       

       
       

       ret
code ends
end start

 

 

3. Numeric Display

the ASSUME CS: code 
Data segment 
  DB 10 DUP ( 0 )
   ; data converted to ASCII code for the deposit of 
Data ends 

code segment 
Start:  MOV AX, 12666 
       MOV BX, Data
        MOV DS, BX
        MOV Si, 0 
       Call DTOC 

       ; display: 8 rows and 3 columns green font 
       MOV DH, 8 
       MOV DL, . 3 
       MOV Cl, 2 
       Call show_str 

       MOV AX, 4c00h
        int 21H 

DTOC: 
        MOV Si, 8
S0:      MOV CX, 10 
        MOV DX, 0 
        div CX
         the Add DX, 30H
         MOV [Si], DL              ; writing a byte 

        MOV CX, AX
         jcxz BREAK 

        On Dec Si
         inc is CX 
        Loop S0 
BREAK: 
        RET 
show_str:  MOV AX, 0B800H     ; start position memory 
          MOV ES, AX
           MOV DI, 0 

          MOV Al, 0A0H       ; calculation line start position 
          MUL DH
           the Add DI, AX 

          MOVAl, 2           ; computed column start position 
          MUL DL
           the Add DI, AX 

          MOV BL, Cl         
        S:  MOV Cl, [Si]
           MOV CH, 0 
          jcxz OK
           MOV  ES: [DI], Cl      ; write data to memory 
          MOV  ES: [DI + . 1 ], BL
           the Add DI, 2 
          inc is Si 
          Loop S 
      OK:  RET 
code ends 
End Start

 

Guess you like

Origin www.cnblogs.com/zhaijiayu/p/11487324.html