标签:
用汇编语言编写一个程序,找出在数据段中预先定义的一组带符号数中的最大数和最小数,并将它们的序号显示到屏幕上(假设序号从0开始)。 例如一组数据定义为: 0A5H,32H,73H, 08H,0FH,90H,0DAH,3BH 则显示结果为:Max:2 Min:5
my solution:
1 data segment 2 str1 db ‘Max : ‘, ‘$‘ 3 str2 db ‘Min : ‘, ‘$‘ 4 num db 0A5H, 32H, 73H, 08H, 0FH, 90H, 0DAH, 3BH 5 res1 db 30h ,‘$‘ 6 res2 db 30h ,‘$‘ 7 max db 00h 8 min db 00h 9 ends 10 11 stack segment 12 dw 128 dup (0) 13 ends 14 15 code segment 16 assume cs:code, ds:data, ss:stack 17 start: 18 mov ax, data 19 mov ds, ax 20 mov es, ax 21 22 mov cx, 07h 23 lea bx, num 24 mov si, 00h 25 mov dl, 00h 26 mov dh, 00h 27 mov al, ds:[bx + si] 28 mov max, al ;初始化alah为num中第一个元素 29 mov min, al 30 mov ah, 01h ;下标flag 31 inc si 32 33 next: 34 mov al, ds:[bx + si] 35 cmp max, al 36 jg j1 37 cmp min, al 38 jl j2 39 jmp j3 40 41 j1: 42 mov max, al 43 mov dh, ah 44 jmp j3 45 46 j2: 47 mov min, al 48 mov dl, ah 49 jmp j3 50 51 j3: 52 inc si 53 inc ah 54 loop next 55 56 done: 57 add res1, dl 58 add res2, dh 59 60 mov ah, 09h 61 lea dx, str1 62 int 21h 63 lea dx, res1 64 mov ah, 9 65 int 21h 66 67 mov ah, 09h 68 lea dx, str2 69 int 21h 70 lea dx, res2 71 mov ah, 9 72 int 21h 73 74 mov ax, 4c00h 75 int 21h 76 end 77 end start
用汇编语言编写一个程序,以统计数据段中预先定义的一组数据中正数,负数和零的个数,并且将结果显示到屏幕上。 例如一组数据定义为: 34H,-3BH,-5AH,72H,0,-2DH,0,66H 则显示结果为:Positive:3 Negative:3 Zero:2
my solution :
1 data segment 2 str db ‘Hello, World!‘, 0Dh, 0Ah, ‘$‘ 3 pkey db "press any key...$" 4 posi db "Positive: $" 5 nega db "Negative: $" 6 zero db "Zero: $" 7 num db 34H, -3BH, -5AH, 72H, 0, -2DH, 0, 66H 8 zeronum db 00h 9 posinum db 00h 10 neganum db 00h 11 ends 12 13 stack segment 14 dw 128 dup(0) 15 ends 16 17 code segment 18 start: 19 assume cs:code, ds:data, ss:stack 20 mov ax, data 21 mov ds, ax 22 mov es, ax 23 24 lea bx, num 25 mov cx, 8 26 jcxz done ;如果cx为0则结束循环 27 28 again: 29 mov al, ds:[bx] ;bx为num首地址,为基址变址寻址方式 30 inc bx 31 cmp al, 0 32 jg above ;如果比较结果大于0,则为正数 33 jz zer ;如果比较结果等于0,则为0 34 inc neganum ;否则对neganum累加 35 loop again 36 37 zer: 38 inc zeronum 39 loop again 40 41 above: 42 inc posinum 43 loop again 44 45 done: 46 mov ah, 09h 47 lea dx, posi 48 int 21H 49 mov ah, 02h 50 mov dl, posinum 51 add dl, 30h ;加上0的ASCLL 码 52 int 21H 53 54 mov ah, 09h 55 lea dx, nega 56 int 21H 57 mov ah, 02h 58 mov dl, neganum 59 add dl, 30h 60 int 21H 61 62 mov ah, 09h 63 lea dx, zero 64 int 21H 65 mov ah, 02h 66 mov dl, zeronum 67 add dl, 30h 68 int 21H 69 70 mov ax, 4c00h 71 int 21h 72 ends 73 74 end start
标签:
原文地址:http://www.cnblogs.com/wushuaiyi/p/4526096.html