假设我必须生成20个随机坐标,20个行号和20个列号。
.model small .data ;///////////////////// VARIABLES ;array of colors color db 01h,02h,03h,04h,05h,06h,0Ah, 0Bh, 0Ch,0Dh,0Eh, 0Fh ;12 colors. star_char db '*', '$' ;coordinates for star. ;center coordinates row_star db 20 dup(?) col_star db 20 dup(?) gen_row_star db ? gen_col_star db ? ;star coordinates go_up db 20 dup(?) go_down db 20 dup(?) go_right db 20 dup(?) go_left db 20 dup(?) ; create temporary storage variables temp_row_star db 20 dup(?) temp_col_star db 20 dup(?) temp_go_up db 20 dup(?) temp_go_down db 20 dup(?) temp_go_right db 20 dup(?) temp_go_left db 20 dup(?) ;boom coordinates delaytime db ? delay_star db 10 delay_printing db 3 .stack 100h total_blink db 5 total_print db 20 ;///// Main code: .code delay proc ;randomize time 5-15secs mov ah, 00h int 1ah mov ax,dx xor dx,dx mov cx, 10 div cx add dl, 15 mov delaytime, dl mov ah, 00 int 1Ah mov bx, dx jmp_delay: int 1Ah sub dx, bx cmp dl, delaytime jl jmp_delay ret delay endp random_coor_star proc mov ah, 00h int 1ah mov ah, 00h int 1ah mov ax,dx xor dx,dx mov cx,10 div cx add dl, 5 mov al,dl mov gen_row_star,al mov ah, 00h int 1ah mov ah, 00h int 1ah mov ax,dx xor dx,dx mov cx,50 div cx add dl,5 mov al,dl mov gen_col_star,al random_coor_star endp clear proc near ;set video mode + clear screen + stop cursor blinking mov al, 03h mov ah, 00h int 10h mov cx, 3200h ;stop cursor blinking mov ah, 01h int 10h ret clear endp complete_print macro r,c,char,color mov dh, r mov dl, c xor bh,bh mov ah,02h int 10h mov al, char mov bh, 0 mov bl, color mov cx, 1 mov ah, 09h int 10h endm main proc mov ax, @data mov ds, ax mov al, 03h mov ah, 00h int 10h ;generate 20 numbers and store in each variable. mov bl,0 transfer: call random_coor_star mov dl, gen_row_star mov [row_star+bx],dl mov dl, gen_col_star mov [col_star+bx],dl call delay cmp bx,20 jl transfer mov ax, 4c00h int 21h main endp end main
有没有办法显示我存储在数组中的所有数字?尝试使用偏移,但没有成功。
接下来是一个显示数字数组的小程序(EMU8086 Intel sytanx):
.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
str db 6 dup('$') ;STRING TO STORE NUMBER CONVERTED INTO STRING.
crlf db 13,10,'$'
.code
;INITIALIZE DATA SEGMENT.
mov ax, @data
mov ds, ax
mov di, offset numbers ;DI POINTS TO THE NUMBERS.
while:
;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
;DISPLAY LINE BREAK.
mov ah, 9
mov dx, offset crlf
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
;------------------------------------------
;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
现在,在前面的代码中,它首先用40个随机数(20对X,Y)填充数组,并显示它们:
.stack 100h
.data
gen_row_star db ?
gen_col_star db ?
array db 40 dup(?) ;STORES 20 PAIRS OF RANDOM NUMBERS.
str db 6 dup('$') ;STRING TO STORE NUMBER CONVERTED INTO STRING.
comma db ',$'
crlf db 13,10,'$'
.code
;INITIALIZE DATA SEGMENT.
mov ax, @data
mov ds, ax
;FILL ARRAY WITH RANDOM NUMBERS.
mov di, offset array
mov bp, 20 ;GENERATE 20 PAIRS OF RANDOM NUMBERS.
fill_array:
call random_coor_star ;NUMBERS RETURN IN gen_row_star AND gen_col_star.
mov al, gen_col_star
mov [ di ], al ;MOVE FIRST NUMBER OF PAIR TO ARRAY (X COORDINATE).
inc di
mov al, gen_row_star
mov [ di ], al ;MOVE SECOND NUMBER OF PAIR TO ARRAY (Y COORDINATE).
inc di
dec bp
jnz fill_array
;DISPLAY ARRAY.
mov di, offset array ;DI POINTS TO THE ARRAY.
mov bp, 20 ;DISPLAY 20 PAIRS OF RANDOM NUMBERS.
while:
;- - - X COORDINATE.
;CONVERT CURRENT NUMBER TO STRING.
call dollars ;FILL "STR" WITH '$'. NECESSARY TO DISPLAY IT.
mov al, [ di ] ;GET CURRENT NUMBER.
mov ah, 0 ;CLEAR AH TO USE AX.
call number2string ;CONVERT AX TO STRING. RESULT IN "STR".
;DISPLAY NUMBER CONVERTED.
mov ah, 9
mov dx, offset str
int 21h
;DISPLAY COMMA.
mov ah, 9
mov dx, offset comma
int 21h
;- - - Y COORDINATE.
inc di ;NEXT NUMBER OF CURRENT PAIR.
;CONVERT CURRENT NUMBER TO STRING.
call dollars ;FILL "STR" WITH '$'. NECESSARY TO DISPLAY IT.
mov al, [ di ] ;GET CURRENT NUMBER.
mov ah, 0 ;CLEAR AH TO USE AX.
call number2string ;CONVERT AX TO STRING. RESULT IN "STR".
;DISPLAY NUMBER CONVERTED.
mov ah, 9
mov dx, offset str
int 21h
;DISPLAY LINE BREAK.
mov ah, 9
mov dx, offset crlf
int 21h
;CHECK IF PROCESS IS OVER.
inc di ;NEXT NUMBER (NEXT PAIR OF COORDINATES).
dec bp
jnz while
;FINISH PROGRAM.
mov ax, 4c00h
int 21h
;------------------------------------------
;DR.DOOM'S RANDOM PROC.
random_coor_star proc
mov ah, 00h
int 1ah
mov ah, 00h
int 1ah
mov ax,dx
xor dx,dx
mov cx,10
div cx
add dl, 5
mov al,dl
mov gen_row_star,al
mov ah, 00h
int 1ah
mov ah, 00h
int 1ah
mov ax,dx
xor dx,dx
mov cx,50
div cx
add dl,5
mov al,dl
mov gen_col_star,al
ret
random_coor_star 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
我试图写一个函数,它以笛卡尔坐标系中的x和y值作为输入,并输出极坐标和三角坐标形式。我希望输出包含指数和正弦/余弦,而不是实际值。例如,如果笛卡尔函数是z=1i,我希望函数输出z=sqrt(2)e^(ipi/4)和z=sqrt(2)(cos(pi/4)Isin(pi/4)。我该怎么做? 函数坐标(x, y) r=sqrt(x.^2 y.^2); θ=atan(y./x); Polarcoord=r
问题内容: 我在JScrollPane中有一个带有自定义表的Swing表单(它只是一个JPanel,而不是JTable子类),并且我试图将其打印出来。如果仅将整个框架发送给打印机,则滚动窗格将被剪切,并且如果将框架调整为滚动窗格的内容大小,则某种内部障碍将使JFrame的高度超过1100像素。 另一种选择是在不将对话框附加到根JFrame的情况下创建对话框的内容窗格,因为在这种情况下,JPanel
#include <stdio.h> int num[10] = { 1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7, 1 << 8, 1 << 9 }; int main (void) { int i; for (i = 0; i < 10; i++) p
问题内容: 我想将数组打印到文件中。 我希望文件看起来像这样的代码完全相似。 假设$ abc是一个数组。 是否有任何一种解决方案,而不是每次外观都是常规的。 PS-我目前使用序列化,但是我想使文件可读,因为使用序列化数组很难读取。 问题答案: 无论是或将返回输出,而不是打印出来的。 PHP手册中的示例 然后,您可以使用保存。或在写入文件时直接将其返回:
我在标签打印机上打印时遇到了问题。下面的代码在一个上打印4个“标签”(附标签图片)。 下面的代码打印到兄弟QL-500标签打印机上。它打印到3.5"乘1.1"标签上。 如果有人能帮我更好地理解代码,那也太好了。 下面是它打印的内容:
为了测试一个程序,我编写了以下语句: