هفته ی پیش توی دانشگاه یکی از اساتید محترم زبان برنامه نویسی اسمبلی تکلیفی رو برای دانشجو ها تعیین کردن که برنامه ای بنویسند به این صورت که طول ارتفاع یک مثلث رو از کاربر بگیره و مثلث رو با استفاده از کارکتر ستاره بکشه و نمایش بده, این برنامه رو من نوشتم و برای کسایی که توی نوشتنش مشکل داشتن و یا واسشون سوال پیش بود اینجا قرار دادم که امیدوارم با خوندنش بتونن ابهام رو برطرف کنن و اگه سوالی دارن توی نظرات از من بپرسن.
سورس رو از اینجا میتونید کپی کنید, یا فایل. رو مستقیم دانلود کنید:
; multi-segment executable file template. data segment ; add your data here! pkey db "press any key...$" inmsg DB "Please enter the triangle's height: $" mval DB 0 hr DB 0 row DB 0 starrow DB 1 sptemp DB 0 strtemp DB 0 strtemp2 DB 0 ends stack segment dw 128 dup(0) ends code segment start: ; set segment registers: mov ax, data mov ds, ax mov es, ax ; add your code here ; my code: LEA DX,inmsg ;asking user for entering the height MOV AH,9 ;asking user for entering the height INT 21H ;asking user for entering the height MOV AH,1 ;getting the height value INT 21H ;ascii character of height is saved in AL reg SUB AL,48 ;converts the ascii code to integer INC AL MOV BL,AL ;height is saved in BL reg (for horizontal spaces) MOV mval,BL MOV BH,AL ADD BH,BH ;BH = 2 * ENTERED_VALUE (for lower part) DEC BH ;real horizontal line value MOV hr,BH MOV CH,1 ;for counting the stars with CH reg MOV CL,0 ;for checking the number of CURRENT stars in a row MOV DL,10 ;going one level down | MOV AH,2 ;going one level down | INT 21H ;going one level down | ;>ENTER MOV DL,13 ;line beginning | MOV AH,2 ;line beginning | INT 21H ;line beginning | rcn:INC row ;|>counts the ROW number and saves in row MOV BH,row ;| MOV BL,mval ;| SUB BL,BH ;| jz j1 ;|>to finish the program! sp:MOV DL,' ' ;| MOV AH,2 ;|>PRINTING SPACE INT 21H ;| DEC BL ;using BL reg for counting the spaces JNZ sp ;prints space till BL > (mval-row) MOV strtemp,0 nxt:MOV DL,'*' ;puts star character in DL reg| MOV AH,2 ;prints the star |>PRINTING one STAR INT 21H ;prints the star | INC strtemp MOV CH,starrow ;checks the number of currently printed stars SUB CH,strtemp JNZ nxt ent:MOV DL,10 ;going one level down | MOV AH,2 ;going one level down | INT 21H ;going one level down | ;>ENTER MOV DL,13 ;line beginning | MOV AH,2 ;line beginning | INT 21H ;line beginning | INC starrow ;| INC starrow ;| ;|> decides how many stars should be printed in NEXT ROW JMP rcn ;| j1:MOV DL,7 ;finishing the program with a beep! MOV AH,2 INT 21H JNZ J1 ; my code end lea dx, pkey mov ah, 9 int 21h ; output string at ds:dx ; wait for any key.... mov ah, 1 int 21h mov ax, 4c00h ; exit to operating system. int 21h ends end start ; set entry point and stop the assembler.
برای دانلود فایل سورس روی دانلود کلیک کنید.