assembly - emu8086 find minimum and maximum in an array -
yes, i've thoroughly searched internet on place this. no, don't understand assembly. i'm 1 week course (microprocessors) , teacher deranged psychopath thinks pisses excellence because we're beginners.
anyway, have come asm code (for emu8086) find minimum , maximum value in array of given size. in sample code, provides (what appears be) data segment contains array named list. claims replace list other lists of different sizes, , our code must able handle it.
here's sample code below. i've highlighted parts i've added, show i've done best solve problem:
; may customize , other start-up templates; ; location of template c:\emu8086\inc\0_com_template.txt org 100h data segment list db 05h, 31h, 34h, 30h, 38h, 37h minimum db ? maximum db ? avarage db ? **size=$-offset list** ends stack segment **;** dw 128 dup(0) **; have no clue supposed do** ends **;** code segment start proc far ; set segment registers: mov ax,data **;** mov ds,ax **;i'm not sure point of is, since i'm supposed programmer, not teacher.** mov es,ax **;** ; add code here **;the number of elements in list size (i think) mov cx,size ;a loop counter, think ;find minimum value in list , store minimum ;begin loop again1: lea si,list lea di,minimum mov al,[si] cmp al,[si+1] if carry flag=1:{i got no idea} loop again1 ;find maximum value in list , store maximum ;something similar other loop, time gotta find max. again2: lea si,list lea di,minimum mov al,[si] cmp al,[si-1] ;??? loop again2 ** ; exit operating system. mov ax,4c00h int 21h start endp ends end start ; set entry point , stop assembler. ret
i'm not positive, think want move size variable after list variable:
data segment list db 05h, 31h, 34h, 30h, 38h, 37h size=$-offset list minimum db ? maximum db ? avarage db ? ends
what give number of bytes between current address ($) , beginning of list variable - giving size (in bytes) of list variable itself. because list array of bytes, size actual length of array. if list array of words, you'd have divide size two. if teacher wrote code perhaps should leave alone.
i'm not entirely clear on why teacher made stack segment, can't think of reason use it, perhaps become clear in future assignment. now, should know dup shorthand duplicate. line of code:
dw 128 dup(0)
is allocating 128 words of memory initialized 0.
the following lines of code:
mov ax,data mov ds,ax mov es,ax
are setting pointers can loop through list. need know that, @ point, ax points beginning of data segment , therefor beginning of list.
as rest... looks have endless loop. need this:
- set si point beginning of list
- set cx length of list, you've done that
- copy first byte [si] ax
- compare ax memory variable minimum
- if ax smaller, copy minimum
- increment , decriment cx
- if cx = 0 (check 0 flag) exit loop, otherwise, go #3
Comments
Post a Comment