#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Assembly language program


    Question:
    Create two procedures: (1) SetColor receives two BYTE parameters: forecolor and backcolor. It calls the SetTextColor procedure from the Irvine32 library. (2) WriteColorChar receives three byte parameters: char, forecolor, and backcolor. It displays a single character, using the color attributes specified in forecolor and backcolor. It calls the SetColor procedure, and it also calls WriteChar from the Irvine32 library. Both SetColor and WriteColorChar must contain declared parameters. Complete the missing part of the code for the two procedures.
    Code:
    TITLE SetColor and WriteColorChar
    
    INCLUDE Irvine32.inc
    
    SetColor PROTO forecolor:BYTE, backcolor:BYTE
    WriteColorChar PROTO char:BYTE,forecolor:BYTE, backcolor:BYTE
    
    .data
    .code
    main PROC
    INVOKE WriteColorChar, 'A', white, blue INVOKE WriteColorChar, 'B', blue, white INVOKE WriteColorChar, 'C', green, black INVOKE WriteColorChar, 'D', yellow, gray INVOKE SetColor, lightGray, black
    call Crlf
    exit main ENDP
    
    WriteColorChar PROC ...
    ...
    WriteColorChar ENDP
    
    SetColor PROC ...
    ...
    SetColor ENDP END main
    Code:
    TITLE SetColor and WriteColorChar
    
    INCLUDE Irvine32.inc
    
    SetColor PROTO forecolor:BYTE, backcolor:BYTE
    WriteColorChar PROTO char:BYTE,forecolor:BYTE, backcolor:BYTE
    
    .data
    .code
    main PROC
    INVOKE WriteColorChar, 'A', white, blue 
    INVOKE WriteColorChar, 'B', blue, white 
    INVOKE WriteColorChar, 'C', green, black 
    INVOKE WriteColorChar, 'D', yellow, gray 
    INVOKE SetColor, lightGray, black
    
    call Crlf
    exit 
    main ENDP
    
    
    WriteColorChar PROC
    
             pop ebp                                                                        ; pop the ebp from the stack
            pop ecx                                                                        ; pop the ecx reg. from the stack
            pop ebx                                                                        ; pop the ebx reg. from the stack
            pop eax                                                                        ; pop the eax reg. from the stack
    
            push eax                                                                ; push Foreground onto the stack
            push ebx                                                                ; push background onto the stack
            push ecx                                                                ; push wChar onto the stack
    
            call SetColor                                                        ; call SetColor
            call WriteChar                                                        ; call WriteChar
    
            ret
    
    WriteColorChar ENDP
    
    
    SetColor PROC 
            push ebp                                                            ; Save calling procedure base pointer
            mov ebp, esp                                                        ; Set base pointer for this procedure
    
            mov ecx, [ebp + 16]                                                 ; Retrieve colors
            mov eax, [ebp + 12]                                                 ; from the stack
    
            mov ebx, 16                                                         ; foreColor + (backColor * 16 )
            mul ebx                                                                        
            add ecx, eax                                                        
    
            mov eax, ecx                                                        ; move ecx reg. into eax re.
            call SetTextColor                                                   ; call SetTextColor to set the fore and back colors
    
            mov eax, [ ebp + 8 ]                                                ; retreive the char from the stack
    		pop ebp                                                             ; Restore base pointer for calling procedure
    
            ret
    
    SetColor ENDP 
    END main
    I'm not familiar with INVOKE and PROTO directive, but I tried my best to make this program. I think I have not used the INVOKE function properly.
    Error I get is A2111: Conflicting parameter definition
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    Corresponding PROTO and PROC directives have to match. Your PROTOs list several arguments but your PROC directives don't. Either remove the arguments in PROTO and handle the arguments manually like you did in SetColor, or define the arguments in PROC matching the PROTO.

    Seeing as your teacher left an ellipsis after the "PROC" you're probably supposed to fill them in.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo