NASM装配计划

时间:2013-04-24 09:57:16

标签: assembly x86 nasm

我正试图用非常沮丧的方式编写NASM程序集...基本上我坚持的是改变输入用$符号绘制的更大数字的数字。所以该程序除了其他方面之外还会读取1到9之间的数字并将其转换为数值并显示一个大的$数字。我已为每一行的每个数字定义了一个位模式,以显示用于绘制数字的$符号模式。所有数字都是7行大小,现在我需要逐步完成位模式,这就是我被困住的地方。到目前为止,这是我的计划。

            bits    16
            org     0x100
            jmp     main    ;Jump to main program
message:    db      'Please enter a number(1-9)',0ah,0dh,'$'
enl_num1:   db      06h,06h,06h,06h,06h,06h,06h ; enlarged 1
enl_num2:   db      04h,0Ah,11h,02h,04h,08h,1Fh ; enlarged 2
enl_num3:   db      0Eh,11h,06h,18h,06h,01h,1Eh ; enlarged 3
enl_num4:   db      01h,02h,04h,0Ah,1Fh,02h,02h ; enlarged 4
enl_num5:   db      1Fh,10h,1Ch,02h,01h,02h,1Ch ; enlarged 4
enl_num6:   db      01h,02h,04h,08h,14h,14h,08h ; enlarged 5
enl_num7:   db      1Fh,01h,02h,04h,08h,10h,10h ; enlarged 7
enl_num8:   db      04h,0Ah,0Ah,04h,0Ah,0Ah,04h ; enlarged 8
enl_num9:   db      0Eh,11h,11h,0Fh,01h,01h,1Fh ; enlarged 9
error_mess: db      '**','$'
output_0:   db      ' ' 
output_d:   db      '$'     

str_to_num:
            xor     bh,bh   ;bh = 0
            cmp     al,39h  ;ASCII for 9
            jg      str_to_num_error    ; > 9 is invalid
            sub     bl,30h  ;convert to numeric
            jl      str_to_num_error    ; < 0 also invalid
            mov     bh,1h   ;succesful completion
str_to_num_error:
            ret             ;return
error:      
            mov     dx,error_mess ;adding ** to number that is not 1-9
            mov     ah,09         ;to display string
            int     21h           ;DOS interrupt
            jmp     message
            ret                   ;return

print_num:  
            mov     cx,8    ; cx=8 loop counter
            mov     al,[si] ;move one byte into al
            push    ax      ;push onto stack
            inc     si      ;point to next byte
            cmp     dh,0    ;test for 0
            jne     not_0
            je      is_0
            loop    print_num   ;decrement cx, repeat loop if cx <>0
            db      ' ',0ah,0dh,'$'
            mov     ah,09   ;to display string
            int     21h     ;DOS interrupt

            ret
not_0:      mov     dx,output_d  ;address of output
            mov     ah,09        ;service - display message
            int     21h          ;DOS system call
            ret
is_0        mov     dx,output_0  ;address of output
            mov     ah,09        ;service - display message
            int     21h          ;DOS system call
            ret

main:       mov     al,00   ;clear the screen
            mov     ah,06
            mov     bh,17h  ;white on blue
            mov     dh,05   ;set row to 5
            mov     dl,10   ;set column to 10
            int     10h     ;screen handling
            mov     dx,message
            mov     ah,09   ;to display string
            int     21h     ;DOS interrupt to display string
            mov     ah,07   ;single char keyboard input
            int     21h     ;DOS interrupt
            call    str_to_num ;convert str to num
            cmp     bh,1h   ;test if bh contains 1
            call    error   ;print error
            cmp     bh,0h   ;test if bh contains 0
            mov     si,bl   ;si contains address of number string
line_loop:  mov     cx,7    ;once for each line
            jmp     print_num ;print the number
            loop    line_loop ;decrement cx, repeat if cx<>0
            int     20h

1 个答案:

答案 0 :(得分:1)

如何显示8 * 7字符之一的Psuedo代码:

ptr = &enl_num1 + (number-1)*7
for row = 0..6 do
  mask = 80h     // start with the left-most bit
  for column = 0..7 do
    if ptr[row] AND mask then
      put_char('$')
    else
      put_char(' ')
    mask >>= 1
  end for
  put_string("\n")
end for

顺便说一下,这不会起作用:

loop    print_num   ;decrement cx, repeat loop if cx <>0
db      ' ',0ah,0dh,'$'
mov     ah,09   ;to display string
int     21h     ;DOS interrupt

如果您将数据与代码交错,则需要跳过数据,否则处理器将尝试执行数据,就好像它是代码一样。